Hi,
Got everything working now…
Thanks to all who have helped!
Here is the working code for the demo:
-- "main.lua" TextScale = 1 TextScaleDir = 1 local composer = require( "composer" ) composer.gotoScene( "sceneAnimatedTextTest" )
-- "sceneAnimatedTextTest.lua" local composer = require( "composer" ) local scene = composer.newScene() local displayText local displayTextScale -- ------------------------------------------------------------------------------------------------------------- function round(x, n) n = math.pow(10, n or 0) x = x \* n if x \>= 0 then x = math.floor(x + 0.5) else x = math.ceil(x - 0.5) end return x / n end -- ------------------------------------------------------------------------------------------------------------- function scene:create( event ) local sceneGroup = self.view TextScale = 1 TextScaleDir = 1 local myRectangle = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight ) myRectangle.strokeWidth = 5 myRectangle:setFillColor( 0.5 ) myRectangle:setStrokeColor( 0, 1, 0 ) sceneGroup:insert( myRectangle ) displayText = display.newText( "Hello World", display.contentCenterX, display.contentCenterY, "Font01.ttf", 20 ) displayText:setFillColor( 0, 1, 0 ) sceneGroup:insert( displayText ) displayTextScale = display.newText( "", display.contentCenterX, 50, "Font01.ttf", 30 ) displayTextScale:setFillColor( 0, 0, 0 ) sceneGroup:insert( displayTextScale ) end -- ------------------------------------------------------------------------------------------------------------- function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then elseif ( phase == "did" ) then local function onEveryFrame( event ) if TextScaleDir == 1 then if TextScale \< 5 then TextScale = TextScale + 0.01 TextScale = round( TextScale, 2 ) displayText.xScale = TextScale displayText.yScale = TextScale else TextScaleDir = 0 displayText.xScale = 5; displayText.yScale = 5; end elseif TextScaleDir == 0 then if TextScale \> 0.01 then TextScale = TextScale - 0.01 TextScale = round( TextScale, 2 ) displayText.xScale = TextScale displayText.yScale = TextScale else TextScaleDir = 1 displayText.xScale = 0.01; displayText.yScale = 0.01; end end displayTextScale.text = tostring( TextScale ) end Runtime:addEventListener( "enterFrame", onEveryFrame ) end end -- ------------------------------------------------------------------------------------------------------------- function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then elseif ( phase == "did" ) then end end -- ------------------------------------------------------------------------------------------------------------- function scene:destroy( event ) local sceneGroup = self.view end -- ------------------------------------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------------------------------------- return scene
Thanks!
JeZxLee