In my app, I have a small circle image that pulses to let the user know what to tap next. I have this image on almost every page so thought it’d be best to modularise it. However, I can’t get the functions without the module to work properly. Here is my code:
scene1.lua
local composer = require( “composer” )
local tapIndicatorFunc = require(“tapIndicatorFunc”)
local scene = composer.newScene()
– “scene:create()”
function scene:create( event )
local sceneGroup = self.view
local backgroundOne = display.newImage(“Images/page2.png”, true)
backgroundOne.x = display.contentWidth/2
backgroundOne.y = display.contentHeight/2
local tapIndicator = display.newImage(“Images/tapButton.png”, true)
tapIndicator.x= display.contentWidth/2 - 250
tapIndicator.y= display.contentHeight/2 + 125
--tapIndicator.alpha = 0
sceneGroup:insert(backgroundOne)
sceneGroup:insert(tapIndicator)
end
--------------------------------------------------------------------------------
– “scene:show()”
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
tapIndicatorFunc.startScale(tapIndicator)
local previous = composer.getSceneName( “previous” )
if previous ~= “main” and previous then
composer.removeScene(previous, false)
end
end
end
--------------------------------------------------------------------------------
– “scene:hide()”
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
end
end
– “scene:destroy()”
function scene:destroy( event )
local sceneGroup = self.view
transition.cancel(scaleTrans)
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
tapIndicatorFunc.lua --my module file
local functionTable = {}
function functionTable.startScale(tapIndicator)
transition.to(tapIndicator, {time=9000, x = 100, alpha=1, onComplete = scaleUp})
end
function functionTable.scaleUp()
scaleTrans = transition.scaleTo( tapIndicator, { xScale=1.1, yScale=1.1, time=500, onComplete=scaleDown} )
end
function functionTable.scaleDown()
scaleTrans = transition.scaleTo( tapIndicator, { xScale=1.0, yScale=1.0, time=500, onComplete=scaleUp } )
end
return functionTable
The startScale function gets called but doesn’t launch the transition and doesn’t move to the onComplete function. Anyone got any idea where I’m going wrong?