scne:create not working properly?

so im trying to transition between a start menu to the game itself

when i click on start in the menu it transitions to the game but it doesnt display everything it only displays the background and one of the images i use to determine the amount of lives left

im currently transitioning my game from a testing file into the scene template file and well it wont display everything that i need (im just working on getting the look of the game right now so i havent added in anything other than the displays into the new scene file)

could someone please explain to me why this isnt working id be greatly appreciative

ive even followed a tutorial and i did exactly what it said to do to get it working but i still get the same issue

here is what i have in my game scene file

local composer = require( "composer" ) local scene = composer.newScene() -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- local gravity = .5 local hitPoints = 3 local timerNum = 0 local loop = 0 local hits = 0 local randomSpawn = math.random(3) local blueTime local greenTime local redTime = 1 local scoreNumber = 0 local background local platform local ball local scoreBoard local score local scoreVisual local life1 local life2 local life3 -- create() function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen background = display.newImageRect("background.png",320, 668 ) background.x = display.contentCenterX background.y = display.contentCenterY sceneGroup:insert(background) platform = display.newImageRect("Platform.png", 360, 35) platform.name = "platform" platform.x = display.contentCenterX platform.y = 505 platform.yScale = display.contentScaleY + 1 sceneGroup:insert(platform) ball = display.newImageRect("square.png", 50, 50) ball.name = "ball" ball.x = display.contentCenterX ball.y = display.contentCenterY sceneGroup:insert(ball) scoreBoard = display.newImageRect("scoreboard.png", 330, 35 ) scoreBoard.x = display.contentCenterX scoreBoard.y = -30 sceneGroup:insert(scoreBoard) score = display.newText( "Score: ", display.contentWidth - 270, display.contentHeight - 510, native.systemFontBold, 20 ) score:setFillColor(255, 255, 255) sceneGroup:insert(score) scoreVisual = display.newText( scoreNumber, 270, display.contentHeight - 510, {width = 128}, native.systemFontBold, 20, {align = "right"}) sceneGroup:insert(scoreVisual) life1 = display.newImageRect("square.png", 20, 20) life1.x = 15 life1.y = 0 sceneGroup:insert(life1) life2 = display.newImageRect("square.png", 20, 20) life2.x = 35 life2.y = 0 sceneGroup:insert(life2) life3 = display.newImageRect("square.png", 20, 20) life3.x = 55 life3.y = 0 sceneGroup:insert(life2) end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene

Are you getting any errors in your console log window?

Rob

i havent had one error that i can find, it doesnt have a window popping up telling me anything and when i click show console it doesnt have any errors either i added some screenshots of what its supposed to look like and what im getting and the graphics are horrible so dont mind them haha 

what its supposed to look like - https://gyazo.com/2af3594b3edcd66f7a0ef2ab4d89d1de

what its currently looking like - https://gyazo.com/742b0da5a4fa25064f1ee54c7fc135ed

the console - https://gyazo.com/58a256f599db6d254d72807ad4729c2c

You should be able to copy/paste that console log text. Better than a screen shot.

Do you have a variable named “debug” any where?

What are you using as an Editor?

Can you run the simulator by hand and not run it through your editor?

Thanks

Rob

Also this:

life3 = display.newImageRect("square.png", 20, 20) life3.x = 55 life3.y = 0 sceneGroup:insert(life2) --\<------ should be life3

Now if you change this line and the red box disappears, then the likely culprit is in the previous scene where you are not inserting the background image into that scene’s sceneGroup. Objects not in a scene group sit on top of all composer objects and a full screen solid image like  your background would block all the composer managed objects hiding under it.

okay so it was the background image from the start image, and if i add the background to sceneGroup i could reuse it in the next scene without having to add another display.newimageRect() right?

i got it working now thanks for the help i just created a seperate scene for the startgame screen and called it in main.lua and now everything is perfect i was able to put it in scengroup and it removed it and made everything work perfect

okay but now i ran into another problem, where my score is displayed the objects that are falling are coming in front of the image now instead of behind the image like it did originally i was using the object:toFront() thing and well its not working its like everytime it calls on my function for spawning the objects falling it pushes it to the back

ive added the object:toFront() thing into the functions thinking it would work aswell but it didnt either

This is a bit more complex issue to deal with. On one hand, you could simply not put the score text and box in sceneGroup so they sit on top, but you would then have to manually create/destroy them in scene:show() and scene:hide() since Composer isn’t managing them. One draw back to this besides you having to do the extra work is since they are not part of the scene, if you’re doing transitions in and out of the game scene, that text/block will not be transitioning with the scene.

The best way to do this is to use multiple groups and put the groups inside of sceneView.  For instance you could at the top of the module do:

local backgroundGroup

local gameGroup

local UIGroup

Then in scene:create() put the background into backgroundGroup:   

backgroundGroup = display.newGroup() backgroundGroup:insert(background) sceneGroup:insert( backgroundGroup ) gameGroup = display.newGroup() sceneGroup:insert( gameGroup ) -- insert any game object like your blocks and circles here UIGroup = display.newGroup() sceneGroup:insert( UIGroup ) -- insert your text objects and their background blocks here.

Later when you need to spawn something, insert it into game group and everything will layer correctly.

Rob

thank you it took me a minute to figure out the order to put them in but i got it figured out now and it works thanks you have been a big help, i was struggling to understand groups but you helped me alot with just that and now i also know how to use the scene template properly to you are the best

Are you getting any errors in your console log window?

Rob

i havent had one error that i can find, it doesnt have a window popping up telling me anything and when i click show console it doesnt have any errors either i added some screenshots of what its supposed to look like and what im getting and the graphics are horrible so dont mind them haha 

what its supposed to look like - https://gyazo.com/2af3594b3edcd66f7a0ef2ab4d89d1de

what its currently looking like - https://gyazo.com/742b0da5a4fa25064f1ee54c7fc135ed

the console - https://gyazo.com/58a256f599db6d254d72807ad4729c2c

You should be able to copy/paste that console log text. Better than a screen shot.

Do you have a variable named “debug” any where?

What are you using as an Editor?

Can you run the simulator by hand and not run it through your editor?

Thanks

Rob

Also this:

life3 = display.newImageRect("square.png", 20, 20) life3.x = 55 life3.y = 0 sceneGroup:insert(life2) --\<------ should be life3

Now if you change this line and the red box disappears, then the likely culprit is in the previous scene where you are not inserting the background image into that scene’s sceneGroup. Objects not in a scene group sit on top of all composer objects and a full screen solid image like  your background would block all the composer managed objects hiding under it.

okay so it was the background image from the start image, and if i add the background to sceneGroup i could reuse it in the next scene without having to add another display.newimageRect() right?

i got it working now thanks for the help i just created a seperate scene for the startgame screen and called it in main.lua and now everything is perfect i was able to put it in scengroup and it removed it and made everything work perfect

okay but now i ran into another problem, where my score is displayed the objects that are falling are coming in front of the image now instead of behind the image like it did originally i was using the object:toFront() thing and well its not working its like everytime it calls on my function for spawning the objects falling it pushes it to the back

ive added the object:toFront() thing into the functions thinking it would work aswell but it didnt either

This is a bit more complex issue to deal with. On one hand, you could simply not put the score text and box in sceneGroup so they sit on top, but you would then have to manually create/destroy them in scene:show() and scene:hide() since Composer isn’t managing them. One draw back to this besides you having to do the extra work is since they are not part of the scene, if you’re doing transitions in and out of the game scene, that text/block will not be transitioning with the scene.

The best way to do this is to use multiple groups and put the groups inside of sceneView.  For instance you could at the top of the module do:

local backgroundGroup

local gameGroup

local UIGroup

Then in scene:create() put the background into backgroundGroup:   

backgroundGroup = display.newGroup() backgroundGroup:insert(background) sceneGroup:insert( backgroundGroup ) gameGroup = display.newGroup() sceneGroup:insert( gameGroup ) -- insert any game object like your blocks and circles here UIGroup = display.newGroup() sceneGroup:insert( UIGroup ) -- insert your text objects and their background blocks here.

Later when you need to spawn something, insert it into game group and everything will layer correctly.

Rob

thank you it took me a minute to figure out the order to put them in but i got it figured out now and it works thanks you have been a big help, i was struggling to understand groups but you helped me alot with just that and now i also know how to use the scene template properly to you are the best