So I am trying my hand at coding in the composer library to change my classes into scenes. Like the main menu class to mode select and then to level select. I ran into a bit of a functional issue trying to use transition.to and positioning the x and y coordinates when my objects are put into the sceneGroup. Here is the code I was using which is based off the template that Corona supplies.
system.getInfo("model") display.setStatusBar(display.HiddenStatusBar) local centerY = display.contentCenterY local centerX = display.contentCenterX local composer = require( "composer" ) local scene = composer.newScene() -- ----------------------------------------------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called. -- ----------------------------------------------------------------------------------------------------------------- -- local forward references should go here -- ------------------------------------------------------------------------------- -- "scene:create()" function scene:create( event ) local sceneGroup = self.view -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. local uiLok = display.newImageRect("mainMenu/homebutton\_hudconnector.png", 713, 404) sceneGroup:insert( uiLok ) local opt = display.newImageRect("mainMenu/homebutton\_options.png", 174, 56) sceneGroup:insert( opt ) local playSel = display.newImageRect("mainMenu/homebutton\_playerS.png", 222, 52) sceneGroup:insert( playerSel ) local fb = display.newImageRect("mainMenu/homebutton\_facebook.png", 50, 50) sceneGroup:insert( fb ) local st = display.newImageRect("mainMenu/homebutton\_store.png", 172, 53) sceneGroup:insert( st ) local myButton = display.newImageRect("buttonSel.png", 150, 50) sceneGroup:insert( myButton ) muteButton.muteTouch() muteButton.unMute() function myButton:touch(event) local phase = event.phase if event.phase == "began" then --playG:scale(.9, .9) transition.to(st, {time = 540, x = 812 }) transition.to(lb, {time = 640, x = 827}) transition.to(opt, {time = 540, x = -99}) transition.to(playSel, {time = 640, x = -114}) transition.to(fb, {time = 250, x = -49}) local game = require("modeSel") return true end end myButton:addEventListener("touch", myButton) end scene:addEventListener( "create", scene ) -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). uiLok.x = 355 uiLok.y = 200 uiLok.alpha = 0 opt.x = 88 opt.y = 255 opt.alpha = 0 playSel.x = 114 playSel.y = 305 playSel.alpha = 0 fb.x = 25 fb.y = 375 fb.alpha = 0 st.x = 620 st.y = 255 st.alpha = 0 myButton.x = 170 myButton.y = 360 myButton.alpha = 0 elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. transition.to(uiLok, {delay = 5500, time = 2000, alpha = 1} transition.to(opt, {delay = 6500, time = 2000, alpha = 1}) transition.to(playSel, {delay = 6500, time = 2000, alpha = 1}) transition.to(fb, {delay = 6500, time = 2000, alpha = 1}) transition.to(st, {delay = 6500, time = 2000, alpha = 1}) transition.to(myButton, {delay = 8000, time = 2000, alpha = 1}) local muteButton = require("muteButton") muteButton.muteSound() end end scene:addEventListener( "show", scene ) -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. opt:removeSelf() opt = nil playSel:removeSelf() playSel = nil fb:removeSelf() fb = nil st:removeSelf() st = nil end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene
When in the IDE, all the variable text names end up being bold text meaning that they are not finding the objects in the create function. I tried scene. and sceneGroup. but neither worked. I’ve tried looking everywhere for a example as to see what a transition looks like in a scene class but with no luck. Can anyone give me any guidance as to what I’m doing wrong?
Now I did get it to work by putting my entire class into the scene:show phase == “will” function and it works like a charm. I know that’s not the right iteration though, so it’s bothering me. Thanks for any help that is provided. Also, in advance, yes I have read all the tutorials provided by the lovely team here at Corona, but I’m still having trouble.
Thanks for reading.