I have this function
local function buttonBackHandler() -- A per-frame event to move the elements local tPrevious = system.getTimer() local function move(event) local tDelta = event.time - tPrevious tPrevious = event.time local xOffset = ( 0.1 \* tDelta ) funny1.x = funny1.x - xOffset funny2.x = funny2.x - xOffset if (funny1.x + funny1.contentWidth) \< 0 then funny1:translate( 1500, 0) end if (funny2.x + funny2.contentWidth) \< 0 then funny2:translate( 1500, 0) end end -- Start everything moving Runtime:addEventListener( "enterFrame", move ); return true end
It’s moving two images just fine…
but I need another button with a function inside to “Stop” the movement
I put this and it did not work
local function buttonHomeHandler() move.stop() return true end
Please help me out with this, I have a problem with sprites and with stop animation
this is the complete code
local storyboard = require( "storyboard" ) local widget = require "widget" local scene = storyboard.newScene() local buttonHome local buttonBack local funny1 local funny2 local function buttonHomeHandler() move.stop() return true end local function buttonBackHandler() -- A per-frame event to move the elements local tPrevious = system.getTimer() local function move(event) local tDelta = event.time - tPrevious tPrevious = event.time local xOffset = ( 0.1 \* tDelta ) funny1.x = funny1.x - xOffset funny2.x = funny2.x - xOffset if (funny1.x + funny1.contentWidth) \< 0 then funny1:translate( 1500, 0) end if (funny2.x + funny2.contentWidth) \< 0 then funny2:translate( 1500, 0) end end -- Start everything moving Runtime:addEventListener( "enterFrame", move ); return true end -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[CREATE SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- function scene:createScene( event ) local group = self.view local background = display.newImage( "backgroundFunny.png" ) group:insert ( background ) buttonHome = widget.newButton{ defaultFile="buttonHome.png", onRelease = buttonHomeHandler } group:insert ( buttonHome ) buttonHome.x = 910 buttonHome.y = 710 buttonBack = widget.newButton{ defaultFile="buttonBack.png", onRelease = buttonBackHandler } group:insert ( buttonBack ) buttonBack.x = 100 buttonBack.y = 710 funny1 = display.newImage( "funnyG1.png" ) funny1:setReferencePoint( display.CenterLeftReferencePoint ) funny1.x = 100; funny1.y = 200 funny2 = display.newImage( "carTireFront.png" ) funny2:setReferencePoint( display.CenterLeftReferencePoint ) funny2.x = 250; funny2.y = 200 end --------------------------------------------------------------ENTER SCENE---------- function scene:enterScene( event ) end -------------------------------------------------------------------------------------- --------------------------------------------------------------EXIT SCENE---------- function scene:exitScene() end -------------------------------------------------------------------------------------- -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[DESTROY SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- function scene:destroyScene( event ) local group = self.view if buttonHome then buttonHome:removeSelf() buttonHome = nil end if buttonBack then buttonBack:removeSelf() buttonBack = nil end end ---------------------------------------------------------------------------------- scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene
–Also, is there any function to move the images from left to right?
– And I found another problem. I have a button that will take me to another scene.
– I press that button and works fine.
– But if I have the images moving, when I use the button to go to another scene, I have an error.
File: …tormbarba/Desktop/How to make an app/speedSample.lua
Line: 31
Attempt to perform arithmetic on field ‘x’ (a nil value)
– Please I need help.
Thanks
Victor