stop my character who falls !

hi everybody.

I have a loop that I can not stop. I would like at the end of my transition character disappears with the bridge. By cons if the bridge goes, I have to check the recurrence of my character, that’s why I use a listener.

in my code I cancel my transition works, but what happens is the command cycles …

I thought about using a timer.performwithdelay but it does not work. thank you if you can help me.

local bridge = display.newRect(200,200,300,300) bridge:setFillColor(1,0,0) bridge.xScale=1 bridge.yScale=1 local character = display.newCircle(200,200,50) character.xScale=1 character.yScale=1 transition.scaleBy(bridge, {tag=bridgefall, time=1000, yScale=-1 , xScale=-1}) local function one() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print("ok") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.cancel("fallCharacter") end local function onEveryFrame(event) &nbsp; &nbsp;&nbsp;&nbsp; print(bridge.xScale) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( bridge.xScale \<= 0.05 ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.scaleBy(character, {tag=fallCharacter, time=500, yScale=-0.15 , xScale=-0.15, onComplete=one})&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end end Runtime:addEventListener("enterFrame",onEveryFrame)

[lua]

local flag = true;

local bridge = display.newRect(200,200,300,300)
bridge:setFillColor(1,0,0)
bridge.xScale=1
bridge.yScale=1

local character = display.newCircle(200,200,50)
character.xScale=1
character.yScale=1

transition.scaleBy(bridge, {tag=“bridgefall”, time=1000, yScale=-1 , xScale=-1})

local function one()
            print(“ok”)
            transition.cancel(“fallCharacter”)
end

local function onEveryFrame(event)
 
   – print(bridge.xScale)
    if ( bridge.xScale <= 0.05 ) then
        if (flag) then
            transition.scaleBy(character, {tag=“fallCharacter”, yScale=-1 , xScale=-1, time=500, onComplete=one})   
            flag = false;
        end
    end
end

Runtime:addEventListener(“enterFrame”,onEveryFrame)

[/lua]

First make sure you put quotation marks around the transition tags.

Second, establish a boolean sentinel value to make sure that the character transition only occurs once

ok thanks for the flag. I didn’t know this but i have an another problem.

i have to probe the scale of the bridge a two time to know his speed, but it seems that the value is only readable once.

if i do print two it result nil…

local bridge = display.newRect(200,200,300,300) bridge:setFillColor(1,0,0) bridge.xScale=1 bridge.yScale=1 local character = display.newCircle(200,200,50) character.xScale,character.yScale=1,1 transition.scaleBy(bridge, {tag=bridgefall, time=1000, yScale=-1 , xScale=-1}) one=print(bridge.xScale) --this work local stopAfter10Seconds = function() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; two=print(bridge.xScale) --this work end timer.performWithDelay( 500, stopAfter10Seconds ) print(two, "youpeeee") --this don't work tree=two - one --this don't work

The print method in Corona SDK does not return anything, so understandably, one and two would be nil.

The correct way of doing it would be:

[lua]
one = bridge.xScale

print(one)

local stopAfter10Seconds = function()

       two = bridge.xScale

       print(two)

end

[/lua]

hi, i have tried what you explain but i need to access the value two after the function and in this case, it’s return to me nil.

local bridge = display.newRect(200,200,300,300) bridge:setFillColor(1,0,0) bridge.xScale=1 bridge.yScale=1 local character = display.newCircle(200,200,50) character.xScale,character.yScale=1,1 transition.scaleBy(bridge, {tag=bridgefall, time=1000, yScale=-1 , xScale=-1}) &nbsp;&nbsp;&nbsp; one= bridge.xScale &nbsp;&nbsp;&nbsp; print(one) &nbsp;&nbsp;&nbsp; stopAfter10Seconds = function()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; two = bridge.xScale &nbsp;&nbsp;&nbsp; return two &nbsp;&nbsp;&nbsp; end timer.performWithDelay( 500, stopAfter10Seconds ) tree=two - one

[lua]

local bridge = display.newRect(200,200,300,300)
bridge:setFillColor(1,0,0)
bridge.xScale=1
bridge.yScale=1

local character = display.newCircle(200,200,50)
character.xScale,character.yScale=1,1

transition.scaleBy(bridge, {tag=bridgefall, time=1000, yScale=-1 , xScale=-1})

    one= bridge.xScale
    print(one)

local two

three = function()     
    local result = two - one
    print(result)
end

stopAfter10Seconds = function()    
    two = bridge.xScale
    three();
end

timer.performWithDelay( 500, stopAfter10Seconds)

 

[/lua]

thanks thanks, but it’s always the same. when i want to use the three value, it’s return nil.

each time, the problem is just move to the next variable…is there not a way easily ?

Can you explain what you are trying to do?

hi,

at a moment my bridge fall randomly in a part of my 2d game, like “pokemon” or “zelda” game.

local tm = math.random(500,8000) local timeFallin = math.random(1500,3000) transition.scaleBy( bridge, {tag="bridgeTransition", yScale=-0.09, xScale=-0.09, time=timeFallin, delay=tm } )

so i have no idea about the time of the transition

so i must probe the scale.x a two time to know this time. with this value i can say to my character the speed of the fall.

the game is a top view with a z axis corresponding of the fall. so i can’t use the physics.  

 BridgeAfterT2T1=BridgeAfterT2-BridgeAfterT1 &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timeOnTest=t2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scaleOnEnd=-0.09 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; speed = BridgeAfterT2T1/timeOnTest &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timeOnTransition = scaleOnEnd/speed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.scaleBy(character, {tag=characterWhoFall, time=timeOnTransition, yScale=scaleOnEnd , xScale=scaleOnEnd})

Isn’t timeFallin the time of transition?

[lua]

local flag = true;

local bridge = display.newRect(200,200,300,300)
bridge:setFillColor(1,0,0)
bridge.xScale=1
bridge.yScale=1

local character = display.newCircle(200,200,50)
character.xScale=1
character.yScale=1

transition.scaleBy(bridge, {tag=“bridgefall”, time=1000, yScale=-1 , xScale=-1})

local function one()
            print(“ok”)
            transition.cancel(“fallCharacter”)
end

local function onEveryFrame(event)
 
   – print(bridge.xScale)
    if ( bridge.xScale <= 0.05 ) then
        if (flag) then
            transition.scaleBy(character, {tag=“fallCharacter”, yScale=-1 , xScale=-1, time=500, onComplete=one})   
            flag = false;
        end
    end
end

Runtime:addEventListener(“enterFrame”,onEveryFrame)

[/lua]

First make sure you put quotation marks around the transition tags.

Second, establish a boolean sentinel value to make sure that the character transition only occurs once

ok thanks for the flag. I didn’t know this but i have an another problem.

i have to probe the scale of the bridge a two time to know his speed, but it seems that the value is only readable once.

if i do print two it result nil…

local bridge = display.newRect(200,200,300,300) bridge:setFillColor(1,0,0) bridge.xScale=1 bridge.yScale=1 local character = display.newCircle(200,200,50) character.xScale,character.yScale=1,1 transition.scaleBy(bridge, {tag=bridgefall, time=1000, yScale=-1 , xScale=-1}) one=print(bridge.xScale) --this work local stopAfter10Seconds = function() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; two=print(bridge.xScale) --this work end timer.performWithDelay( 500, stopAfter10Seconds ) print(two, "youpeeee") --this don't work tree=two - one --this don't work

The print method in Corona SDK does not return anything, so understandably, one and two would be nil.

The correct way of doing it would be:

[lua]
one = bridge.xScale

print(one)

local stopAfter10Seconds = function()

       two = bridge.xScale

       print(two)

end

[/lua]

hi, i have tried what you explain but i need to access the value two after the function and in this case, it’s return to me nil.

local bridge = display.newRect(200,200,300,300) bridge:setFillColor(1,0,0) bridge.xScale=1 bridge.yScale=1 local character = display.newCircle(200,200,50) character.xScale,character.yScale=1,1 transition.scaleBy(bridge, {tag=bridgefall, time=1000, yScale=-1 , xScale=-1}) &nbsp;&nbsp;&nbsp; one= bridge.xScale &nbsp;&nbsp;&nbsp; print(one) &nbsp;&nbsp;&nbsp; stopAfter10Seconds = function()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; two = bridge.xScale &nbsp;&nbsp;&nbsp; return two &nbsp;&nbsp;&nbsp; end timer.performWithDelay( 500, stopAfter10Seconds ) tree=two - one

[lua]

local bridge = display.newRect(200,200,300,300)
bridge:setFillColor(1,0,0)
bridge.xScale=1
bridge.yScale=1

local character = display.newCircle(200,200,50)
character.xScale,character.yScale=1,1

transition.scaleBy(bridge, {tag=bridgefall, time=1000, yScale=-1 , xScale=-1})

    one= bridge.xScale
    print(one)

local two

three = function()     
    local result = two - one
    print(result)
end

stopAfter10Seconds = function()    
    two = bridge.xScale
    three();
end

timer.performWithDelay( 500, stopAfter10Seconds)

 

[/lua]

thanks thanks, but it’s always the same. when i want to use the three value, it’s return nil.

each time, the problem is just move to the next variable…is there not a way easily ?

Can you explain what you are trying to do?

hi,

at a moment my bridge fall randomly in a part of my 2d game, like “pokemon” or “zelda” game.

local tm = math.random(500,8000) local timeFallin = math.random(1500,3000) transition.scaleBy( bridge, {tag="bridgeTransition", yScale=-0.09, xScale=-0.09, time=timeFallin, delay=tm } )

so i have no idea about the time of the transition

so i must probe the scale.x a two time to know this time. with this value i can say to my character the speed of the fall.

the game is a top view with a z axis corresponding of the fall. so i can’t use the physics.  

 BridgeAfterT2T1=BridgeAfterT2-BridgeAfterT1 &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timeOnTest=t2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scaleOnEnd=-0.09 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; speed = BridgeAfterT2T1/timeOnTest &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timeOnTransition = scaleOnEnd/speed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transition.scaleBy(character, {tag=characterWhoFall, time=timeOnTransition, yScale=scaleOnEnd , xScale=scaleOnEnd})

Isn’t timeFallin the time of transition?