Hi,
For understand the composer, i have made a simple app with each basic function possible :
- transition
- timer
- listener
- physics
- objects
I have my main.lua with redirect to menu.lua and menu.lua redirect to scene1.lua
when i access to my level.lua it’s said that my character are a nill value but i don’t understand why…could you help me ? Thanks.
--scene1.lua local composer = require( "composer" ) local scene = composer.newScene() local params -- -- Start the composer event handlers -- function scene:create( event ) local sceneGroup = self.view params = event.params local background=display.newRect(0,0,3000,3000) -- background:setFillColor(1,1,1) local function createcharacter() local character=display.newCircle(800,250,20) character:setFillColor(0,0,0)--black end local circle=display.newCircle(240,500,20) circle:setFillColor(0,0,1)--black physics.start() physics.setGravity( 0, 6 ) physics.addBody( circle, "dynamic" ) local button={} for i=1,2 do button[i]=display.newCircle(600,500,40) button[i].myId=(i) button[i]:setFillColor(1,0,0) end button[1].x=100--pause button[2].x=450--restart the game button[1]:setFillColor(1,1,0) local cntSwipe=0 local cnt=1 local textCntSwipe= display.newText("Level", 50,410,native.systemFontBold, 35) textCntSwipe:setFillColor(1,1,1) local function countTimer() --count the time cnt=cnt+1 textCntSwipe.text = cntSwipe end --function countTimer local function displacement(character) local function displacementEnd(character) character.transition=transition.to(character, {time=1500,x=250, onComplete=function() displacement(character) end}) end character.transition=transition.to(character, {time=1500,x=50, onComplete=function() displacementEnd(character) end}) end--displacement -- displacement(character) local function testPosition() print(character.x) end Runtime:addEventListener("enterFrame", function() testPosition(character) end) local function touchCharacter(event) if event.phase =="ended" then target = event.target if target.myId ==1 then print("cela") composer.gotoScene( "menu", { time = 2500, effect = "fade", params = params } ) elseif target.myId == 2 then composer.gotoScene( "menu", { time = 2500, effect = "fade", params = params } ) print("aussu") end--if end--if end--touchCharacter -- setup a page background, really not that important though composer -- crashes out if there isn't a display object in the view. -- sceneGroup:insert(background,character,circle,button) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is off screen and is about to move on screen elseif phase == "did" then createcharacter() displacement(character) for i=1,#button do button[i]:addEventListener("touch",touchCharacter) end mytimer=timer.performWithDelay( 1000, countTimer,-1) -- Called when the scene is now on screen -- -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then timer.cancel(mytimer) Runtime:removeEventListener("touch",touchCharacter) Runtime:removeEventListener("enterFrame",testPosition) transition.cancel(character.transition) -- Called when the scene is on screen and is about to move off screen -- -- INSERT code here to pause the scene -- e.g. stop timers, stop animation, unload sounds, etc.) elseif phase == "did" then -- Called when the scene is now off screen end end function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's "view" (sceneGroup) -- -- INSERT code here to cleanup the scene -- e.g. remove display objects, remove touch listeners, save state, etc end ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ------------------------------------------------------------------------------- return scene

