General Game Dev Questions!

Hello All,

This is my first post in the forums but yes I’ve been browsing around a lot! I have some general questions, and although I have been researching and digging through this forum, I have started to get confused || maybe I’m just overwhelmed. Here are my questions:

  1. I’m developing a game, and need scenes. I know the most efficient way to go about scenes is to use the storyboard API, is that correct? I’ve heard of Director, but since it’s not directly supported by Corona, I believe the Storyboard API is a good choice.

  2. I would like to create code and re-use it, especially when I start to have tons of levels in my game. In web dev, there are PHP includes, and I believe the closest thing I could utilize is something called “modules”? Is this correct, or is there a different way? A good example is if I have my main character in every level, I only should modify that one LUA file, not every single level.

  3. Memory management. I know the basics to this topic, and yes I’ve read the “memory management 101” post, but I’m still worried that I’m not implementing it correctly. For example, on the main screen of my game, the memory usage is around 165. Once I enter my game it shoots up to 450-500 respectively, but once I go back to the main menu, it goes to around 400… and no lower. Should / could I get it to go back to 165? It would make sense if yes I could, because once I leave the game and go back I should be able to clean all memory from the game.

  4. Groups. Can I just remove a whole group, instead of each individual object? Actually I just answered my own question, last night I used a for loop to remove every object in a group… Thanks! (is that best practice though?)

  5. Is there some template out there that is a game, uses the storyboard API (if that is in fact best practice), uses modules to avoid repeating code (if that is also best practice)? Ghosts vs. Monsters is the closest, but I don’t think it uses the Storyboard API.

  6. SO far, these are my questions, but I do have more!

[import]uid: 129334 topic_id: 24120 reply_id: 324120[/import]

Hi Mark - welcome to the community!

  1. Either Director or Storyboard are both good, solid options and whichever one you like the feel of better you should consider using, especially as this is your first app. (From what I’ve gathered, correct me if I am wrong!)

  2. That is correct, we have modules. We have some great blog posts by Jon Beebe about modularization that you may want to read.

  3. Is there any chance you have forgotten to remove an object or perhaps cancel a timer or the like?

  4. I believe groups can be removed without doing it by individual object without any issue. I don’t think either method is better although I’m not 100% certain and will test this in the morning for you.

  5. Not that I am aware of, no - although I can’t say for sure on that, none of my templates use Storyboard (yet) but I’m unsure on other peddlers :wink:

I hope this helps and look forward to your other questions!

Peach :slight_smile: [import]uid: 52491 topic_id: 24120 reply_id: 97364[/import]

Hi Peach! Thanks for the reply, I’ve spent some time over the weekend to work on these issues.

  1. I’ve chosen director for this first project, because at the end of the day, it worked for me. The Storyboard API just seemed too complicated for me, but I will try it out again in my next app. Here’s the GAME TEMPLATE I used, which I felt was easy to understand (code wise):
    http:

    2) I finally got modules to work for me! Although I’m not sure how ‘efficient’ my code is, it works for me. I read Jon Beebe’s article here http:</http:>. But I understood the example by this thread (see insert.code’s example:http:

    3) I found my big memory leak, it was a runtime event that I put inside a for loop. BUT, when I go back and forth from one scene to another, my memory usage goes up +1… This seems like a memory leak to me, but idk, it’s not as bad as my other memory leak.

    4) How do you remove a whole group (and all it’s items in it?) Basically, I just want to remove ALL items within a GROUP and any TABLES… is that possible? In director, I put all my objects in a group called :
    [lua]local localGroup = display.newGroup()[/lua]
    So does that mean when I leave that secene, all the items in that group are removed?

    5) When I see a simple GAME TEMPLATE using the storyboard API, I will check it out. Ok, I think the default STORYBOARD API sample is already available, but for some reason it was hard to understand (but maybe I’d understand it better, now…) [import]uid: 129334 topic_id: 24120 reply_id: 97832[/import] </http:></http:>

Hey Mark,

I think you forgot a link at the end of point 1 but am glad to hear you are going OK with this. I understand Storyboard can be a bit overwhelming at first and there is nothing wrong with working up to it later :slight_smile:

Glad to hear modularization is working for you - by reading Jon Beebe’s post you will be off to a great start I am sure.

Your memory usage going up could be related to different things, but 1 what? If it is 1 byte just changing scenes I’d say that was definitely negligible.

If you are using Director then the group “localGroup” is automatically cleared of everything in it when you change scenes, yes. If you have things that are NOT in the group (timers, Runtime listeners, any objects you have left out for some reason, etc) then you will want to manually remove them right before you call the scene change.

Does this make sense? :slight_smile: [import]uid: 52491 topic_id: 24120 reply_id: 97864[/import]

  1. woops, here’s the link to the GAME TEMPLATE I used:
    http://developer.anscamobile.com/code/game-template

  2. I’m using the memory usage from this link (it’s the memory leak tips 101:
    http://blog.anscamobile.com/2011/08/corona-sdk-memory-leak-prevention-101/

and the code:

[code]
local monitorMem = function()

collectgarbage()
print( "MemUsage: " … math.round(collectgarbage(“count”)) )

local textMem = system.getInfo( “textureMemoryUsed” ) / 1000000
print( "TexMem: " … textMem )
end

Runtime:addEventListener( “enterFrame”, monitorMem )[/code]

Notice I added a math.round() around the collectgarbage(“count”) - this rounded number is what I am seeing. So, for example, on my main menu, it will say “385”, then I go to a scene and immediately jump back to the main menu. Now I see “386”… for the memory usage.

  1. Yes that all makes perfect sense! Thanks!

[import]uid: 129334 topic_id: 24120 reply_id: 97870[/import]

Peach said, “If you are using Director then the group “localGroup” is automatically cleared of everything in it when you change scenes, yes. If you have things that are NOT in the group (timers, Runtime listeners, any objects you have left out for some reason, etc) then you will want to manually remove them right before you call the scene change.”

My question: I have a file / scene named “level01.lua” that contains multiple modules (such as the enemy and main character modules". I understand that all objects in “localGroup” will automatically be cleared when you change scenes, BUT what if I have objects also in the “localGroup” but inside each module? Are those cleared as well? [import]uid: 129334 topic_id: 24120 reply_id: 97876[/import]

Yes, if they are in the localGroup then they will be cleared as well regardless of where they were spawned from.

I haven’t checked out that game template previously but I will, I see it was created by a finalist of the 2011 Techority 48 Hour Challenge :slight_smile: [import]uid: 52491 topic_id: 24120 reply_id: 97892[/import]

Awesome!! that is good to hear (“if they are in the localGroup then they will be cleared as well regardless of where they were spawned from.”)

Woohoo!

Yes, this was the closest Director template I could find, that was very easy to understand… there were a few files / code that I deleted, but I understood why.

Thanks! [import]uid: 129334 topic_id: 24120 reply_id: 97895[/import]

Why do I have to do memory management, how come it can’t just be as easy as “leave a scene, all cleaned”??? I have memory leaks that are almost ridiculous, like if I go back and forth scenes my game slows down badly…!

It comes down to me having to zone in and find the memory leaks, but it’s preventing me from actually continuing my game…

Maybe I will just wait until the end to do memory optimization / leakage [import]uid: 129334 topic_id: 24120 reply_id: 98456[/import]

Hehe, unfortunately you have to do SOME of the fiddly parts yourself :wink:

How high are you memory leaks that it is slowing down badly? What device are you using? On a mid-high end device there shouldn’t be noticeable slowdown even with your average memory leaks without a LOT of scene changing.

How many MB is texture memory? What’s the change there on a scene change? [import]uid: 52491 topic_id: 24120 reply_id: 98479[/import]

PEACH, here’s an example use case:

  • I start my game and on the main menu the Memory / Texture reads:
    Memory: 146 | Texture: 5

  • I start LEVEL 1 , and it now reads:
    Memory: 362 | Texture: 23

  • I exit this level and go to my main menu again:
    Memory: 341 | Texture: 11

  • Back to LEVEL 1 :
    Memory: 366 | Texture: 23

  • Back to Main Menu
    Memory:341 | Texture: 11

Now at this point if I do this cycle a few more times, the game starts to REALLY slow down. I want to “guess” and say my FPS is going down drastically, but I don’t know how to check my FPS.

Do you have any ideas on what all this means?

BTW, I will narrow down my memory leaks soon, meaning I will comment out modules and find out exactly where I’m messing up. BUT any suggestions will help… [import]uid: 129334 topic_id: 24120 reply_id: 98674[/import]

Hmmmm. How much audio are you using? (I’m wondering if you aren’t disposing of it and this is perhaps an issue.)

What about sprites?

Here’s a thread that shows how to see current FPS:
http://developer.anscamobile.com/forum/2012/01/24/display-current-fps

Peach :slight_smile: [import]uid: 52491 topic_id: 24120 reply_id: 98704[/import]

Hi Peach,

Good news! I believe I’ve resolved or at least alleviated my memory leak. Before, going back and forth scenes really slowed down my game drastically, and this was very easy to reproduce.

I started a new project and slowly added things into my game, but the difference was I used the code to find the current FPS (the link you just posted on FPS) instead of my other memory code.

Basically what I found was I was applying the function to call my memory code, in every scene! The code you showed me from the link, didn’t call the function in every scene, just in the main.lua file.

Now, I haven’t been able to reproduce my issue like before, which is a good sign!

I have been worrying about this issue for weeks…

Thanks for your communication and help. [import]uid: 129334 topic_id: 24120 reply_id: 98988[/import]

Hey Mark

I just finished and published my first game and had similar questions. On the memory leak question I ended up buying the Corona Profiler from http://www.mydevelopersgames.com/site/. It’s a little clunky (if you’re used to tools like Instruments) but allowed me to narrow down the leak to a particular line in my code and take it from there.

Also, given my success with the profiler, I just purchased their Cider IDE which allows you to set breakpoints and debug - it sure beats using a text editor.

I’m not affiliated with the company that sells these, just a happy customer. Their tools have certainly helped accelerate my Corona development - hadn’t realized how spoiled I was with xCode, Eclipse etc etc.

Good luck

Mike [import]uid: 10948 topic_id: 24120 reply_id: 98990[/import]

HI javaboyjunior, cool, I’ll check it out! But why do I need this, in all reality? Will I just have a cool UI and some fancy numbers, when really I just need values of my FS and Memory?

In terminal, it shows you the line of code, or where there’s an issue, that you need to fix. Sometimes it’s hard to tell, but with some patience and good debugging practices, I don’t see any reason to buy another program. [import]uid: 129334 topic_id: 24120 reply_id: 98993[/import]

FPS* not FS, haha [import]uid: 129334 topic_id: 24120 reply_id: 98994[/import]

I guess it’s a combination of personal preference and code complexity. Say you have a few thousand, maybe even tens of thousands of lines of code and some complicated game mechanics. On the memory usage do you want to continually play your game for minutes at a time watching them memory print out and then guessing which of the 50 things happening on screen or in your code at the time the memory spiked was the cause? Or do you want a graph of memory allocations over time, see the spike click on the graph, see the line number where that memory was allocated? I’d rather do the latter.

For debugging it’s a similar situation. Add print statements, look in the console for values, see you’ve missed one, add a new print statement, restart your game etc or add a breakpoint in a debugger, have the game pause when it hits the breakpoint, be able to see the value of all variables in memory, even change them and then continue from that point…

I’m not saying it’ll work for you, just that it made my life easier. Going back to a text editor and printing variables to the console was a huge step backwards given the sophistication of some of the IDEs around these days (XCode, Eclipse, IntelliJ, Visual Studio etc etc). I’d rather spend my time coding, not hunting down problems.

Anyway, just my experience after a month with Corona, no more than that. YMMV

Good luck with your game

Mike
[import]uid: 10948 topic_id: 24120 reply_id: 99003[/import]