transition.to listerner and function

Hi everyone,

how do you do to listen a transition.to

I would like have a red circle when my square have a scale of 1.2 and when the scale is minder or upper, the circle become white.

is it possible ?

local circle = display.newCircle ( 150, 150, 100, 100 ) local square = display.newRect( 0, 0, 100, 100 ) transition.scaleBy( square, { xScale=2, yScale=2, time=10000 } )

Sorry for my english, it’s not my mother tongue !

use onComplete - this is a function that is triggered when a transition is complete.

transition.to(square, { time = 1000, alpha = 1, onComplete = function() print("Hello world") end })

thanks for your response, but in this case i don’t want a function onComplete because i want that the circle become red during the transition with a specific parametrer (in my case an xScale and yScale =1.2)  and not at the end …

your response is what i have resquested.

sorry and thanks

good day

local paint = { 1, 0, 0 } local square = display.newRect( 100, 100, 30, 30 ) square.fill = paint   transition.scaleTo( square, { xScale=2, yScale =2, time=1000 } ) transition.to(square, { xScale=1.5, yScale =1.5, onComplete = function() display.newCircle ( 150, 250, 30, 30 ) end })

hi,

transition.scaleTo( square, { xScale=2, yScale =2, time=1000 } ) transition.to(square, { xScale=-2, yScale =-2, onComplete = transition.cancel })

I still have a problem …
I can not, for example, to stop the transition when my square -2 size, animation persite still to be

my goal is to get to have a square tapering up to a certain value and then stop the animation “scaleTo” for my square remains in this small

what’s the good solution ?

I think you need to have an enter frame event listener for this.

For example:

[lua]local square = display.newRect( 100, 100, 30, 30 )

transition.scaleTo( square, { xScale=10, yScale =10, time=3000 } )

local function onEveryFrame( event )

    if square.yScale > 5 then

        square:setFillColor(1,1,0)

    end

end

Runtime:addEventListener( “enterFrame”, onEveryFrame )[/lua]

thanks but how do you do to stop this transition when the yScale of the square is  = 5 while keeping my square displayed with this scale of 5

I hope I understand correctly:

[lua]local square = display.newRect( 100, 100, 30, 30 )

transition.scaleTo( square, {tag = “squareTransition”, xScale=10, yScale =10, time=3000 } )

local function onEveryFrame( event )

    if square.yScale > 5 then

        square:setFillColor(1,1,0)

        transition.cancel(“squareTransition”)

    end

end

Runtime:addEventListener( “enterFrame”, onEveryFrame )[/lua]

thanks a lot, I learned a lot of things with your code snippet notammnet the possibility of appointing a transition tag to play with afterwards

maybe just a last question, why this animation is not stopped when the value exceeds -1?

 local square = display.newRect( 100, 100, 100, 100 )           transition.scaleBy( square, {tag = "squareTransition", xScale =-2, yScale =-2, time=3000 } )           local function onEveryFrame( event )         if square.yScale \> -1 then             square:setFillColor(1,1,0)             transition.cancel("squareTransition")               end     end           Runtime:addEventListener( "enterFrame", onEveryFrame )

Square yScale is 1 when it starts which is higher than -1 so transition is cancelled immediately.

Probably you want to do less than -1? _ if square.yScale < -1 then _

Put print(square.yScale) inside onEveryFrame and see the value change in real time.

sorry for my stupid question, i have found the solution

&nbsp;&nbsp;&nbsp; local square = display.newRect( 100, 100, 100, 100 ) &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; transition.scaleBy( square, {tag = "squareTransition", xScale =-2, yScale =-2, time=3000 } ) &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; local function onEveryFrame( event ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if square.yScale \<= 0.1 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; square:setFillColor(1,1,0) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.cancel("squareTransition") &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; Runtime:addEventListener( "enterFrame", onEveryFrame )

we answered at the same time :slight_smile:

yes I compare a value of 0-1 square.yScale and not from -1 to 1
it is only xScale Yscale and which can be reduced to negative numbers for the function ScaleBy

so I can reduce my square to a value smaller than its form intiale 100,100

I did what you said and two strange things

in fact the animation does not always end the same way, the size of the square is not always the same.

through your code print(square.yScale)  seen I get different values ​​for each launch
0.00666666
0.00455555

0.002588888

0.088866666

out yet that could not happen because I ask <= 0.04

local variable = math.random(0,300) &nbsp;&nbsp;&nbsp; local square = display.newRect( variable, variable, variable, variable ) &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; transition.scaleBy( square, {tag = "squareTransition", xScale =-1, yScale =-1, time=600 } ) &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; local function onEveryFrame( event ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(square.yScale) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if square.yScale \<= 0.04 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- square:setFillColor(1,1,0) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.cancel("squareTransition") &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; end

Its update every 30 or 60 times per second so its not 100% accurate but should be pretty close.

You can set it to the scale you need after you cancel the transition if you need to be so accurate:

[lua]local function onEveryFrame( event )

      print(square.yScale)

        if square.yScale <= 0.04 then

            transition.cancel(“squareTransition”)

            square.yScale = 0.04

            square.xScale = 0.04

        end

    end[/lua]

yes it is better, but is it impossible to make a corona in the same animation every time ?

My final test is to reproduce a ball falls into a hole and I would like to have the same animation every time.

Do you see visual different?

Maybe make a new thread and write about your concerns with sample? Probably you will not get input from others in this thread because it has become long.

the best solution i found but i I’m having a problem because I wanted to compare a specific yScale and define an action based on the value …
but if corona responds to an approximate value, I can not rely on this parameter Yscale …

Specifically, if the ball falls I would like at a certain value Yscale I make an animation where it breaks

local square = display.newRect( variable, variable, 100, 100 ) &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; transition.scaleBy( square, {tag = "squareTransition", xScale =-1, yScale =-1, time=1000, alpha = 0.1 } ) &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local function onEveryFrame( event ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(square.yScale) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if square.yScale \<= 0.1 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; square:setFillColor(1,0,0) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.cancel("squareTransition") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if square.yScale ~= 0.1 then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; square.alpha = 0 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end

ok thanks for your help

use onComplete - this is a function that is triggered when a transition is complete.

transition.to(square, { time = 1000, alpha = 1, onComplete = function() print("Hello world") end })