Help with storyboard / composer.

Hello, I am a newbie. I am writing a game for andriod and have done pretty much all. Now when I wanted to make the game over screen and the main menu I got to know about storyboard / composer. All my game is in the main.lua file now.

  1. Which one should I use storyboard or composer?

  2.  How do I copy all my code of the game play which is currently in the main.lua file ? should I be copying it under scene:create (Using the composer’s template) or under scene.show? I know I also have to add my variables to the group indivisually. But do I also have to add the functions to the group? and what about the variabled created inside a function, do I have to add them too? 

I hope I cleared my question. I made a mess of my code. It’s going to give me a hard time making the scenes :’( any help would be appreciated. Thanks

  1. You should only use Composer. Storyboard has been deprecated and will get no further support. We will be removing it from the core very soon. You do have the option to use the open source version of it from our GitHub repository, but I don’t recommend it as we won’t be providing support for it.

  2. You put the things where they make logical sense. Creation stuff should go in scene:create(). Things that shouldn’t happen until the scene is on screen should go in scene:show(), etc.  Every sample template, every sample app is well commented about what goes where and the guides are very detailed on this.  Spawning things (happens after the game is on screen) would be triggered by event started in scene show (timers and such).

Rob

@amdriod95,

  1. Use composer

  2. Since your game is monolithic (all in main.lua), you’d probably be fine putting in scene:create(), but be sure to put all objects in the display group provided by composer or composer will not know about the objects and won’t manage them.

-Ed

@roaminggamer Thanks for your reply, do I have to put all the functions and variables in display groups? and I am also using physics in my game so should I be starting the physics in the main.lua file or in the scene where I need it?

My advice is to download our Sample Game Project from our github repository:

https://github.com/coronalabs/sample-game-project

Look through it and see how it’s constructed. Pay careful attention to game.lua. It has comments in it and sample code that shows you where to put things.

Rob

Rob, I have gone through the game project and gave a good look to each of the file. I see that that when you press the “I lose” button it ends the game and to to that you have made an event listner.

however in my case, I do not want a button to end a game. I want to end my game when health is equals to 0.

This is what I’m trying to do:

if health == 0 then

composer.removeScene(“gamePlay”)

composer.gotoScene( “gameOver” )

end

it does not seem to work with an if statement. how can I get around this?

if health == 0 then     composer.gotoScene( "gameOver" ) end

First, you cannot remove the scene you’re in or there won’t be anything to show. Remove your game play scene in gameOver or in your menu scene before you go to the gamePlay scene.

My next thought/questions is around where are you checking to see if health == 0?

Oh okay I get about removing the scene.  here is what I’m doing with the health:

I am checking for the collision detection with my character. If it gets the collision then it -1 from the health and then checks to see if the health is 0. Here is what my code looks like:

local function walkCollision(self, event)

  if event.phase == “began” then

–if event.target ==“walk” and event.object.type == “food” then

if event.other.type == “food” then

print (“eating”)

score = score + 100

updateScore(event)

local function playsoundd()

audio.play(eatSnd)

end 

timer.performWithDelay(200, playsoundd)

event.other:removeSelf()

transition.to ( event.other, { time=1000,y=screenBottom+ 5000} )

walk:setSequence(“eat”)

walk:play()

timer.performWithDelay (100,standAgain)

else

health = health -1

showHealth()

walk:setSequence(“hit”)

walk:play()

timer.performWithDelay (100,standAgain)

print(“Oeeeeeeeeeeeee”)

if health == 0 then

– THIS IS WHERE I AM TRYING TO GO TO THE NEXT GAME OVER SCENE---------------------------------------------

print(“GAME OVER”)

end

It really helps to have your code indented and use code formatting when posting code. Please use the <> in the edit bar (with Bold, Italic, etc. ) and paste your code in there:
 

local function walkCollision(self, event) if event.phase == "began" then --if event.target =="walk" and event.object.type == "food" then if event.other.type == "food" then print ("eating") score = score + 100 updateScore(event) local function playsoundd() audio.play(eatSnd) end timer.performWithDelay(200, playsoundd) event.other:removeSelf() transition.to ( event.other, { time=1000,y=screenBottom+ 5000} ) walk:setSequence("eat") walk:play() timer.performWithDelay (100,standAgain) else health = health -1 showHealth() walk:setSequence("hit") walk:play() timer.performWithDelay (100,standAgain) print("Oeeeeeeeeeeeee") if health == 0 then -- THIS IS WHERE I AM TRYING TO GO TO THE NEXT GAME OVER SCENE--------------------------------------------- print("GAME OVER") end

I’m assuming that you didn’t show the rest of the function on purpose.  Are you getting any of the prints (“Oeeeeeeeeeeee”, “GAME OVER”)?

Rob

Sorry about posting the code like that, I’m new to coding and having been following the infinite skill mobile game development. They say to use ctrl+] for intending which dosen’t work in the current outlaw’s version. Thanks for the little tip.

Yes I am geting the prints “Oeeeeeeeeee” and “GAME OVER” on the console. so the code is working. this is the whole collision function I posted here. I can post other functions too if you want me to?

and the Game Over scene I’m trying to go to is working if I put it in my main.lua file so the problem is also not with the gameOver scene file that is okay. I’m just having issues going to a diffrent scene

Are you getting any errors in your console log?

If you’re getting the game over print, there is no reason it won’t go to the new scene unless a) the scene doesn’t exist or b) the scene has errors.

Rob

I just recorded my screen to demonstrate whats going on. please check out this video

http://www.dailymotion.com/video/x33pec3

you will see I am not getting any errors and my gameOver scene is working fine but I am not able to go to the next scene :’( it’s frustrating now. Its been more than 24 hours me trying to get around it. Please help

Oh my I got it what was going wrong! my background was on top of everything so the scene was being called under the background hence giving out no errors and displaying on screen but still not visible :stuck_out_tongue:

I got it working by setting my background to back i.e object:toBack()

Thank you @Rob for putting in effort to help me with this!

:smiley:

  1. You should only use Composer. Storyboard has been deprecated and will get no further support. We will be removing it from the core very soon. You do have the option to use the open source version of it from our GitHub repository, but I don’t recommend it as we won’t be providing support for it.

  2. You put the things where they make logical sense. Creation stuff should go in scene:create(). Things that shouldn’t happen until the scene is on screen should go in scene:show(), etc.  Every sample template, every sample app is well commented about what goes where and the guides are very detailed on this.  Spawning things (happens after the game is on screen) would be triggered by event started in scene show (timers and such).

Rob

@amdriod95,

  1. Use composer

  2. Since your game is monolithic (all in main.lua), you’d probably be fine putting in scene:create(), but be sure to put all objects in the display group provided by composer or composer will not know about the objects and won’t manage them.

-Ed

@roaminggamer Thanks for your reply, do I have to put all the functions and variables in display groups? and I am also using physics in my game so should I be starting the physics in the main.lua file or in the scene where I need it?

My advice is to download our Sample Game Project from our github repository:

https://github.com/coronalabs/sample-game-project

Look through it and see how it’s constructed. Pay careful attention to game.lua. It has comments in it and sample code that shows you where to put things.

Rob

Rob, I have gone through the game project and gave a good look to each of the file. I see that that when you press the “I lose” button it ends the game and to to that you have made an event listner.

however in my case, I do not want a button to end a game. I want to end my game when health is equals to 0.

This is what I’m trying to do:

if health == 0 then

composer.removeScene(“gamePlay”)

composer.gotoScene( “gameOver” )

end

it does not seem to work with an if statement. how can I get around this?

if health == 0 then &nbsp;&nbsp;&nbsp; composer.gotoScene( "gameOver" ) end

First, you cannot remove the scene you’re in or there won’t be anything to show. Remove your game play scene in gameOver or in your menu scene before you go to the gamePlay scene.

My next thought/questions is around where are you checking to see if health == 0?

Oh okay I get about removing the scene.  here is what I’m doing with the health:

I am checking for the collision detection with my character. If it gets the collision then it -1 from the health and then checks to see if the health is 0. Here is what my code looks like:

local function walkCollision(self, event)

  if event.phase == “began” then

–if event.target ==“walk” and event.object.type == “food” then

if event.other.type == “food” then

print (“eating”)

score = score + 100

updateScore(event)

local function playsoundd()

audio.play(eatSnd)

end 

timer.performWithDelay(200, playsoundd)

event.other:removeSelf()

transition.to ( event.other, { time=1000,y=screenBottom+ 5000} )

walk:setSequence(“eat”)

walk:play()

timer.performWithDelay (100,standAgain)

else

health = health -1

showHealth()

walk:setSequence(“hit”)

walk:play()

timer.performWithDelay (100,standAgain)

print(“Oeeeeeeeeeeeee”)

if health == 0 then

– THIS IS WHERE I AM TRYING TO GO TO THE NEXT GAME OVER SCENE---------------------------------------------

print(“GAME OVER”)

end