Advice for handling levels and question about sounds

I am using composer and I am about to work on different levels.  Start them on lowest level then go on up.

So I thought of this way.

in Play.lua

do a counter say from 1 to 10.

call actualPlay.lua (pass it counter)

if successful return (and less than 10) Congrats you passed level counter - now get ready for the next level

else - sorry you could not pass level counter.

end do

Congrats you passed all 10 levels if successful return on 10th time.

I tried doing the levels in the actual game play scene but had lots of problems.

Any SHORT simple example out there for levels if this is not the right way to do it?

I am also using composer.variable name to hold some data.

Question on sounds.

I got a few Homer simpson sounds from a website that says they are free to use.  Are they REALLY free to use or are they protected by the people who does “The Simpsons”?

Any good example on how to handle sounds, I was told you are supposed to load them first then play them later.

Thank you!

Well, my idea didn’t work.

for current_level = 1,5 do

   local levelText = display.newText("Level " … current_level,0,0,native.systemFontBold,16)

   …

   local function decreaseTime()

   …

      if (time == -1) then

         composer.gotoScene(“ifc.startPlay”)

      end

   end

   timer.performWithDelay(1000,decreaseTime,6)

end

I was hoping to call ifc.startPlay 5 times but all it does is print level out 5 times then goes to ifc.startPlay.

Can I have an example to see how I am supposed to do this?

Do I need to put that all inside of a timer?

Thanks!

Its best to ask different questions in different threads as your sound question is completely different.

DISCLAIMER: Corona Labs cannot offer answers to legal questions like this.  If community members (or staff members) respond to this, they are doing so based on their own knowledge and advice.  They are personal opinions and do not represent Corona Labs.

As far as your loop goes, what you are doing is in very rapid succession (fractions of a second), you are creating 5 display.newText() objects and creating 5 timers all at the same time that will all expire in 1 second.  Each one decreases time by 1 and you have it decrease time by one each time.  One second later, 5 timers fire at virtually the same time.  Since I don’t know what value time started with, it’s now 5 less than it was.  If in that check time exactly matches -1, then it will fire to the next scene.

Basically the timer needs to be outside the loop and let it be something that fires 6 times and when done, goto your new scene.

Yes but I want the scene to be called 5 times ( which is why I added outer loop ) you know once for each level.

You don’t need a loop for this.  When the game is over increment your level counter by one, save it so that your ifc.startPlay module can get the current_level counter and behave accordingly.

Rob

Oh ok. So I need to change my design because right now I have one lua file that is setting up the game with all the info then I was going to call the game and if won call it again. So you are saying I should handle the different levels all inside the game. I can try that.

Do you have a sample of a small game that does this?

Thank you for your help.

I don’t have a small example handy.  There are two different ways to do this.  Have one “game” scene that takes it’s level number, perhaps some level specific data.  A game like Candy Crush for instance is really the same logic every scene for the most part.  Or you can take a game like Angry Birds and it might make sense to have a separate scene/.lua file for each level since so many things have to be positioned in different places.

But in any case, there is a point where the level ends.  If it’s successful you then go to the next scene if not go to the game over.  You would almost never queue up all your scenes to visit in a linear fashion the way you are doing.

Rob

You said “You would almost never queue up all your scenes to visit in a linear fashion the way you are doing.”  and “If it’s successful you then go to the next scene if not go to the game over.”

OH!  A big lightbulb went off.  This is the difference between C programming and object programming language like Corona SDK that I have been struggling with.

Now I understand.   Don’t do a loop forcing it to go 5 times (checking to see if failed to get out).  Instead When the game ends check to see if last level, if not push to next level.  Yes, I understand now!

Thank you so much!

One last question, what is the easiest way to “clear the screen” to start the next level?

Thanks!

Hi @universalenglishinchina,

Well, there’s not really one “easiest way” to clear the screen for the next level, because every app is different. If you’re using Composer, then normal display objects which have been inserted into the scene will be cleared when you exit the scene. However, you must still manually perform some clean-up tasks like:

  1. Cancelling timers or transitions in progress.

  2. Stopping audio files and disposing all audio handles.

See this guide section for more information:

http://docs.coronalabs.com/guide/system/composer/index.html#management

Best regards,

Brent

Well, my idea didn’t work.

for current_level = 1,5 do

   local levelText = display.newText("Level " … current_level,0,0,native.systemFontBold,16)

   …

   local function decreaseTime()

   …

      if (time == -1) then

         composer.gotoScene(“ifc.startPlay”)

      end

   end

   timer.performWithDelay(1000,decreaseTime,6)

end

I was hoping to call ifc.startPlay 5 times but all it does is print level out 5 times then goes to ifc.startPlay.

Can I have an example to see how I am supposed to do this?

Do I need to put that all inside of a timer?

Thanks!

Its best to ask different questions in different threads as your sound question is completely different.

DISCLAIMER: Corona Labs cannot offer answers to legal questions like this.  If community members (or staff members) respond to this, they are doing so based on their own knowledge and advice.  They are personal opinions and do not represent Corona Labs.

As far as your loop goes, what you are doing is in very rapid succession (fractions of a second), you are creating 5 display.newText() objects and creating 5 timers all at the same time that will all expire in 1 second.  Each one decreases time by 1 and you have it decrease time by one each time.  One second later, 5 timers fire at virtually the same time.  Since I don’t know what value time started with, it’s now 5 less than it was.  If in that check time exactly matches -1, then it will fire to the next scene.

Basically the timer needs to be outside the loop and let it be something that fires 6 times and when done, goto your new scene.

Yes but I want the scene to be called 5 times ( which is why I added outer loop ) you know once for each level.

You don’t need a loop for this.  When the game is over increment your level counter by one, save it so that your ifc.startPlay module can get the current_level counter and behave accordingly.

Rob

Oh ok. So I need to change my design because right now I have one lua file that is setting up the game with all the info then I was going to call the game and if won call it again. So you are saying I should handle the different levels all inside the game. I can try that.

Do you have a sample of a small game that does this?

Thank you for your help.

I don’t have a small example handy.  There are two different ways to do this.  Have one “game” scene that takes it’s level number, perhaps some level specific data.  A game like Candy Crush for instance is really the same logic every scene for the most part.  Or you can take a game like Angry Birds and it might make sense to have a separate scene/.lua file for each level since so many things have to be positioned in different places.

But in any case, there is a point where the level ends.  If it’s successful you then go to the next scene if not go to the game over.  You would almost never queue up all your scenes to visit in a linear fashion the way you are doing.

Rob

You said “You would almost never queue up all your scenes to visit in a linear fashion the way you are doing.”  and “If it’s successful you then go to the next scene if not go to the game over.”

OH!  A big lightbulb went off.  This is the difference between C programming and object programming language like Corona SDK that I have been struggling with.

Now I understand.   Don’t do a loop forcing it to go 5 times (checking to see if failed to get out).  Instead When the game ends check to see if last level, if not push to next level.  Yes, I understand now!

Thank you so much!

One last question, what is the easiest way to “clear the screen” to start the next level?

Thanks!

Hi @universalenglishinchina,

Well, there’s not really one “easiest way” to clear the screen for the next level, because every app is different. If you’re using Composer, then normal display objects which have been inserted into the scene will be cleared when you exit the scene. However, you must still manually perform some clean-up tasks like:

  1. Cancelling timers or transitions in progress.

  2. Stopping audio files and disposing all audio handles.

See this guide section for more information:

http://docs.coronalabs.com/guide/system/composer/index.html#management

Best regards,

Brent