Why text won`t transition

Hi all,

Why this does not work/transition?

local myGroup = display.newGroup() local myText = display.newText(myGroup, "Hello World!", 100, 200, native.systemFont, 16 ) myText:setFillColor( 1, 0, 0 ) -- LATER ON transition.to (myText, {time = 1000, xScale = 1.5, yScale = 1.5} -- OR LATER ON transition.to (myText, {time = 1000, alpha = 0}

How to make text transition (text is a member of myGroup )?

Thanks!!

G

Hey,

don’t know if what you posted is exactly your code. But you are missing brackets at the end of you transition calls. (you should get an error for this as well)

transition.to (myText, {time = 1000, xScale = 1.5, yScale = 1.5}) transition.to (myText, {time = 1000, alpha = 0})

Hi,

you have missed the end brackets off the transition, you should be getting a runtime error in the console:

should be:

transition.to (myText, {time = 1000, xScale = 1.5, yScale = 1.5} )
transition.to (myText, {time = 1000, alpha = 0} )

Hi bubble,

No runtime errors.

Brackets are not the problem here.

Is the code where myText create within a function? If so, myText will be local to that function and not accessible later on to any other functions.

Hi Nick,

Yes, it is inside a function.

But I have predeclared myText before that function…

local myText ------- LATER ON local function setUpDisplay() myText = display.newText(myGroup, "Hello World!", 100, 200, native.systemFont, 16 ) myText:setFillColor( 1, 0, 0 ) end

It is interesting that when I link myText via addEventListener to the function where you do the transition.to, then everything works well…

So “event.target” must be present… I do not why…

I have even tried to:

  1. Make setUpDisplay() as global function

OR

  1. return myText at the end of  setUpDisplay() function

Does not work…

You know what is very very interesting!

At the same place in my code when I change:

transition.to(myText, {time = 1000, alpha = 0}) ---------- THIS DOES NOT WORK to: myText.alpha = 0 ---------------- THIS WORKS

Obviously myText scope is not the issue here… otherwise  myText.alpha = 0 would NOT work!

Any ideas?

Whole thing looks like this in  COMPOSER:

local composer = require( “composer” )

local scene = composer.newScene()


– All code outside of the listener functions will only be executed ONCE unless “composer.removeScene()” is called


– Local forward references should go here


local myText

local function gameOver()

     transition.to(myText, {time = 1000, alpha = 0)    ---- DOES NOT WORK

     

     myText.alpha = 0 -----------------------------  THIS WORKS… WHY ?

end

– “scene:create()”
function scene:create( event )

local sceneGroup = self.view

– Initialize the scene here
– Example: add display objects to “sceneGroup”, add touch listeners, etc.
end

– “scene:show()”
function scene:show( event )

local sceneGroup = self.view
local phase = event.phase

if ( phase == “will” ) then
– Called when the scene is still off screen (but is about to come on screen)
elseif ( phase == “did” ) then
– Called when the scene is now on screen
– Insert code here to make the scene come alive
– Example: start timers, begin animation, play audio, etc.

myText = display.newText(myGroup, “Hello World!”, 100, 200, native.systemFont, 16 )
myText:setFillColor( 1, 0, 0 )

myText.x = centerX

myText.y = centerY

gameOver()

end
end

– “scene:hide()”
function scene:hide( event )

local sceneGroup = self.view
local phase = event.phase

if ( phase == “will” ) then
– Called when the scene is on screen (but is about to go off screen)
– Insert code here to “pause” the scene
– Example: stop timers, stop animation, stop audio, etc.
elseif ( phase == “did” ) then
– Called immediately after scene goes off screen
end
end

– “scene:destroy()”
function scene:destroy( event )

local sceneGroup = self.view

– Called prior to the removal of scene’s view
– Insert code here to clean up the scene
– Example: remove display objects, save state, etc.
end


– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )


return scene

Your transition does have a missing curly bracket.

Your code:

transition.to(myText, {time = 1000, alpha = 0)

Correct code:

transition.to(myText, {time = 1000, alpha = 0})

I’ve just copied your code into a lua file and it worked for me once I added the extra bracket (and after I made a few necessary changes for it to run as the code you’ve posted is incomplete - there are variables such as myGroup and centerX which you haven’t defined anywhere in the code sample).

On a separate note, when posting code into the forum could you please use the <> button so that it stays correctly formatted and is easier for people to read.

Hi Alan,

Thanks for your reply.
Here are some facts:

  1. There were NO errors, therefore there was NO missing brackets.

  2. I have added bracket (no help).

  3. I solved this inserting transition.to in a seperate function, and calling that local function.

Maybe this is (latest) Corona build snag.

Regarding formating, sorry, I am sometimes on a cellphone.

Gogi

Two things: 

  1.  YES you do have a missing bracket in the code you posted.  

  2. You are inserting myText into something called myGroup, which doesn’t exist.

Your corrected code:

local composer = require( "composer" ) local scene = composer.newScene() -- ----------------------------------------------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called -- ----------------------------------------------------------------------------------------------------------------- -- Local forward references should go here -- ------------------------------------------------------------------------------- local myText local function gameOver() transition.to(myText, {time = 1000, alpha = 0}) ---- DOES NOT WORK end -- "scene:create()" function scene:create( event ) local sceneGroup = self.view -- Initialize the scene here -- Example: add display objects to "sceneGroup", add touch listeners, etc. end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Called when the scene is now on screen -- Insert code here to make the scene come alive -- Example: start timers, begin animation, play audio, etc. myText = display.newText(sceneGroup, "Hello World!", 100, 200, native.systemFont, 16 ) myText:setFillColor( 1, 0, 0 ) myText.x = centerX myText.y = centerY gameOver() end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen) -- Insert code here to "pause" the scene -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view -- Insert code here to clean up the scene -- Example: remove display objects, save state, etc. end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene

Thanks JON.
I just wanted to point out that trans.to does not trigger… posted code was corrected…
Anyways, thanks.

Hey,

don’t know if what you posted is exactly your code. But you are missing brackets at the end of you transition calls. (you should get an error for this as well)

transition.to (myText, {time = 1000, xScale = 1.5, yScale = 1.5}) transition.to (myText, {time = 1000, alpha = 0})

Hi,

you have missed the end brackets off the transition, you should be getting a runtime error in the console:

should be:

transition.to (myText, {time = 1000, xScale = 1.5, yScale = 1.5} )
transition.to (myText, {time = 1000, alpha = 0} )

Hi bubble,

No runtime errors.

Brackets are not the problem here.

Is the code where myText create within a function? If so, myText will be local to that function and not accessible later on to any other functions.

Hi Nick,

Yes, it is inside a function.

But I have predeclared myText before that function…

local myText ------- LATER ON local function setUpDisplay() myText = display.newText(myGroup,&nbsp;"Hello World!", 100, 200, native.systemFont, 16 ) myText:setFillColor( 1, 0, 0 ) end

It is interesting that when I link myText via addEventListener to the function where you do the transition.to, then everything works well…

So “event.target” must be present… I do not why…

I have even tried to:

  1. Make setUpDisplay() as global function

OR

  1. return myText at the end of  setUpDisplay() function

Does not work…

You know what is very very interesting!

At the same place in my code when I change:

transition.to(myText, {time = 1000, alpha = 0}) ---------- THIS&nbsp;DOES NOT WORK to: myText.alpha = 0 ----------------&nbsp;THIS WORKS

Obviously myText scope is not the issue here… otherwise  myText.alpha = 0 would NOT work!

Any ideas?

Whole thing looks like this in  COMPOSER:

local composer = require( “composer” )

local scene = composer.newScene()


– All code outside of the listener functions will only be executed ONCE unless “composer.removeScene()” is called


– Local forward references should go here


local myText

local function gameOver()

     transition.to(myText, {time = 1000, alpha = 0)    ---- DOES NOT WORK

     

     myText.alpha = 0 -----------------------------  THIS WORKS… WHY ?

end

– “scene:create()”
function scene:create( event )

local sceneGroup = self.view

– Initialize the scene here
– Example: add display objects to “sceneGroup”, add touch listeners, etc.
end

– “scene:show()”
function scene:show( event )

local sceneGroup = self.view
local phase = event.phase

if ( phase == “will” ) then
– Called when the scene is still off screen (but is about to come on screen)
elseif ( phase == “did” ) then
– Called when the scene is now on screen
– Insert code here to make the scene come alive
– Example: start timers, begin animation, play audio, etc.

myText = display.newText(myGroup, “Hello World!”, 100, 200, native.systemFont, 16 )
myText:setFillColor( 1, 0, 0 )

myText.x = centerX

myText.y = centerY

gameOver()

end
end

– “scene:hide()”
function scene:hide( event )

local sceneGroup = self.view
local phase = event.phase

if ( phase == “will” ) then
– Called when the scene is on screen (but is about to go off screen)
– Insert code here to “pause” the scene
– Example: stop timers, stop animation, stop audio, etc.
elseif ( phase == “did” ) then
– Called immediately after scene goes off screen
end
end

– “scene:destroy()”
function scene:destroy( event )

local sceneGroup = self.view

– Called prior to the removal of scene’s view
– Insert code here to clean up the scene
– Example: remove display objects, save state, etc.
end


– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )


return scene

Your transition does have a missing curly bracket.

Your code:

transition.to(myText, {time = 1000, alpha = 0)

Correct code:

transition.to(myText, {time = 1000, alpha = 0})

I’ve just copied your code into a lua file and it worked for me once I added the extra bracket (and after I made a few necessary changes for it to run as the code you’ve posted is incomplete - there are variables such as myGroup and centerX which you haven’t defined anywhere in the code sample).

On a separate note, when posting code into the forum could you please use the <> button so that it stays correctly formatted and is easier for people to read.