square transition problem

Hi,

i have a problem to do a simple task : a transition of a square to produce a shadow effect of a projectile.

my problem is that the square1 is delete too fast. Normaly, he must be deleted after the local deplacement and not before…why?

    local square = display.newRect( 100, 100, 30, 30 )     square.yScale=1     square.xScale=1     local deplacement=transition.to( square, { time=500, x=150, y=10, yScale=2, xScale=2, onComplete=deplacement, } )     display.remove (square)     square=nil     local square2 = display.newRect( 150, 100, 60, 60 )     square2.yScale=1     square2.xScale=1     square2.alpha=0.9     local deplacement2=transition.to( square2, { delay=500, time=500, x=300, y=100, yScale=0.5, xScale=0.5, onComplete=deplacement2 } )

 

half solved.

for the first part but I found… the second square that should appear after a period of time I can not find …

 local square = display.newRect( 100, 100, 30, 30 )     square.yScale=1     square.xScale=1     local function removeob( square )     square:removeSelf()     end     local deplacement=transition.to( square, { time=200, x=150, y=100, yScale=2, xScale=2, onComplete=removeob } ) --square 2 appear to fast in same time than square!!!         local function app()         local square2=display display.newRect( 150, 100, 60, 60 )         local deplacement2=transition.to( square2, { time=200, x=200, y=100, yScale=0.5, xScale=0.5})     end          timer.performWithDelay(190, app)     

 

sorry to pollute the forum but no one for me?

in the code you only called a timer to show the second square without waiting for the first square transition to be done first.

you should change into something like this:

 local function app() local square2=display display.newRect( 150, 100, 60, 60 ) local deplacement2=transition.to( square2, { time=200, x=200, y=100, yScale=0.5, xScale=0.5}) end local square = display.newRect( 100, 100, 30, 30 ) square.yScale=1 square.xScale=1 local function removeob() square:removeSelf() timer.performWithDelay(190, app) end local deplacement=transition.to( square, { time=200, x=150, y=100, yScale=2, xScale=2, onComplete=removeob } )

thanks but your solution don’t work,

The square2 don’t make the transition. idon’t knwo why because what you wrote is correct and logic.

can you tell me more what happened after you change the code? Does it gives any error, or just no transition?

no error.

just the second transition and the local square2 which does not appear

try this:

 local function app() local square2=display display.newRect( 150, 100, 60, 60 ) local deplacement2=transition.to( square2, { time=200, x=200, y=100, yScale=0.5, xScale=0.5}) end local square = display.newRect( 100, 100, 30, 30 ) local function removeob(obj) obj:removeSelf() timer.performWithDelay(190, app) end local deplacement = transition.to( square, { time=200, x=150, y=100, yScale=2, xScale=2, onComplete=function() removeob(square) end} )

I tried your code but still the same concern.
I corrected the line with remove (obj) by remove (square)

 local function app()         local square2=display display.newRect( 150, 100, 60, 60 )         local deplacement2=transition.to( square2, { time=200, x=200, y=100, yScale=0.5, xScale=0.5})     end local square = display.newRect( 100, 100, 30, 30 ) local function removeob(square)     square:removeSelf()     timer.performWithDelay(190, app) end local deplacement = transition.to( square, { time=200, x=150, y=100, yScale=2, xScale=2, onComplete=function()     removeob(square) end} )

try print something inside the remove function to check whether the function runs correctly

local function removeob(square) square:removeSelf() print('call square 2') app() //try calling it without any timer end

it’s seems that the local square2 is not considered

result = nil

local function removeob(square)     square:removeSelf()     app()     print(square2) end

i have modified my code with but it’s the same

 local function app()         local square2=display display.newRect( 150, 100, 60, 60 )         local deplacement2=transition.to( square2, { time=200, x=200, y=100, yScale=0.5, xScale=0.5})         return square2, deplacement2     end

writing different and the problem is the local essai wich don’t work

 local square = display.newRect( 100, 100, 30, 30 )  local essai = function (square, square2, deplacement2)         square:removeSelf()         local square2=display display.newRect( 150, 100, 60, 60 )         local deplacement2=transition.to( square2, { time=200, x=200, y=100, yScale=0.5, xScale=0.5})     end local deplacement = transition.to( square, { time=200, x=150, y=100, yScale=2, xScale=2, onComplete=essai})

In your app function you have display written twice…the code posted by Jonathan should work with that error corrected.

[lua]

local function app()

      local square2 = display.newRect( 150 , 100 , 60 , 60 )

local deplacement2=transition.to( square2, { time= 200 , x= 200 , y= 100 , yScale= 0.5 , xScale= 0.5 })

end

local square = display.newRect( 100 , 100 , 30 , 30 )

local function removeob(obj)

    obj:removeSelf()

    timer.performWithDelay( 190 , app)

end

local deplacement = transition.to( square, { time= 200 , x= 150 , y= 100 , yScale= 2 , xScale= 2 , onComplete=function()

    removeob(square)

end} )

[/lua]

thanks nick sherman

the code I wrote earlier works now

thank you both

 local square = display.newRect( 100, 100, 30, 30 )  local function essai(square)         square:removeSelf()         local square2=display.newRect( 150, 100, 60, 60 )         local deplacement2=transition.to( square2, { time=200, x=200, y=100, yScale=0.5, xScale=0.5})     end local deplacement = transition.to( square, { time=200, x=150, y=100, yScale=2, xScale=2, onComplete=essai })

thanks again a nice jump effect

local eventx=300 local eventy=300 local persox=100 local persoy=100 if eventx==persox then nouvelleCoordonneex=eventx else nouvelleCoordonneex=eventx-persox end if eventy==persoy then nouvelleCoordonneey=eventy else nouvelleCoordonneey=eventy-persoy end  local function jump()  local square = display.newImage( "my2.png" )  square.x=persox  square.y=persoy  local function essai(square)         square:removeSelf()         local square=display.newImage( "my2.png" )          square.x=nouvelleCoordonneex          square.y=nouvelleCoordonneey         local deplacement2=transition.to( square, { time=250, x=eventx, y=eventy, yScale=0.5, xScale=0.5, transition=easing.outElastic})     end local deplacement = transition.to( square, { time=100, x=nouvelleCoordonneex, y=nouvelleCoordonneey, yScale=2, xScale=2, onComplete=essai, transition=easing.inBounce }) end jump()

half solved.

for the first part but I found… the second square that should appear after a period of time I can not find …

 local square = display.newRect( 100, 100, 30, 30 )     square.yScale=1     square.xScale=1     local function removeob( square )     square:removeSelf()     end     local deplacement=transition.to( square, { time=200, x=150, y=100, yScale=2, xScale=2, onComplete=removeob } ) --square 2 appear to fast in same time than square!!!         local function app()         local square2=display display.newRect( 150, 100, 60, 60 )         local deplacement2=transition.to( square2, { time=200, x=200, y=100, yScale=0.5, xScale=0.5})     end          timer.performWithDelay(190, app)     

 

sorry to pollute the forum but no one for me?

in the code you only called a timer to show the second square without waiting for the first square transition to be done first.

you should change into something like this:

 local function app() local square2=display display.newRect( 150, 100, 60, 60 ) local deplacement2=transition.to( square2, { time=200, x=200, y=100, yScale=0.5, xScale=0.5}) end local square = display.newRect( 100, 100, 30, 30 ) square.yScale=1 square.xScale=1 local function removeob() square:removeSelf() timer.performWithDelay(190, app) end local deplacement=transition.to( square, { time=200, x=150, y=100, yScale=2, xScale=2, onComplete=removeob } )

thanks but your solution don’t work,

The square2 don’t make the transition. idon’t knwo why because what you wrote is correct and logic.

can you tell me more what happened after you change the code? Does it gives any error, or just no transition?