Ok, after a couple of hours I have this code which runs perfectly on the Simulator,
but I can’t figure out how to add a colored outline to the text using the functions “, lineR, lineG, lineB,” values?
Here is the code in all its glory:
-- "main.lua" TextObjectsIndex = -1; TotalNumberOfCachedTexts = 100 TextObjects = {} for i = 1, TotalNumberOfCachedTexts do TextObjects[i] = nil end TextScale = 1 TextScaleDir = 1 local composer = require( "composer" ) composer.gotoScene( "sceneAnimatedTextTest" )
-- "mathFunct.lua" local MathFunct={}; function MathFunct.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 -- ------------------------------------------------------------------------------------------------------------- return MathFunct
-- "visualsFunct.lua" local VisualsFunct={}; function VisualsFunct.drawTextOntoScene( text, font, size, fillR, fillG, fillB, lineR, lineG, lineB, textX, textY ) if TextObjectsIndex \< (TotalNumberOfCachedTexts-1) then TextObjectsIndex = TextObjectsIndex + 1 else TextObjectsIndex = 0 end -- How to add outline to text using lineR, lineG, LineB ? local i = TextObjectsIndex TextObjects[i] = display.newText( text, textX, textY, font, size ) TextObjects[i]:setFillColor( fillR, fillG, fillB ) return TextObjects[i] end -- ------------------------------------------------------------------------------------------------------------- return VisualsFunct
-- "sceneAnimatedTextTest.lua" local composer = require( "composer" ) local scene = composer.newScene() local mathFunct = require( "mathFunct") local visualsFunct = require( "visualsFunct") local displayTextScale -- ------------------------------------------------------------------------------------------------------------- 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 ) sceneGroup:insert( visualsFunct.drawTextOntoScene( "Hello World", "Font01.ttf", 20, 0, 1, 0, 0, 0, 0, display.contentCenterX, display.contentCenterY ) ) 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 = mathFunct.round( TextScale, 2 ) TextObjects[TextObjectsIndex].xScale = TextScale TextObjects[TextObjectsIndex].yScale = TextScale else TextScaleDir = 0 TextObjects[TextObjectsIndex].xScale = 5; TextObjects[TextObjectsIndex].yScale = 5; end elseif TextScaleDir == 0 then if TextScale \> 0.01 then TextScale = TextScale - 0.01 TextScale = mathFunct.round( TextScale, 2 ) TextObjects[TextObjectsIndex].xScale = TextScale TextObjects[TextObjectsIndex].yScale = TextScale else TextScaleDir = 1 TextObjects[TextObjectsIndex].xScale = 0.01; TextObjects[TextObjectsIndex].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