Firstly, thanks for all of the responses. I’ve tried both methods but can’t get either working so here’s my code if you don’t mind taking a look to see what I’m doing wrong:
First Method"Don’t put image in the storyboard scene’s display group":
local ballImg, ballTrans local function rotateBall() ballImg.rotation = 0 ballTrans = transition.to(ballImg, {rotation=360, time=2000, onComplete=rotateBall}) end local function loadNextScene() storyboard.loadScene( "scene", false ) storyboard.gotoScene( "scene" ) end ------------------- STORYBOARD ------------------- function scene:createScene( event ) local group = self.view ballImg = display.newImageRect("/images/ballImg.png", 30.125, 30) -- POSITION ballImg.x, ballImg.y = 100, 100 end function scene:enterScene( event ) timer.performWithDelay(1, rotateBall) timer.performWithDelay(10, loadNextScene) end function scene:exitScene( event ) if ballTrans then transition.cancel(ballTrans) end end
Second Method : “Using enterFrame”:
local ballImg local function rotateBall( event ) ballImg.rotation = ballImg.rotation + 10 end local function loadNextScene() storyboard.loadScene( "scene", false ) storyboard.gotoScene( "scene" ) end ------------------- STORYBOARD ------------------- function scene:createScene( event ) ballImg = display.newImageRect("/images/ballImg.png", 30.125, 30) -- POSITION ballImg.x, ballImg.y = 100, 100 end function scene:enterScene( event ) Runtime:addEventListener("enterFrame", rotateBall) timer.performWithDelay(10, loadNextScene) end function scene:didExitScene( event ) Runtime:removeEventListener("enterFrame", rotateBall) ballImg:removeSelf() end