is it possible ?

hi,

first i must spawn an character

local character1=display.newImage(...) character1.x=100

next i have to do a special transition with a function , i must remove my character and spawn an another with a different position based on event.x

local function transitionSpecial() local character2=display.newImage(...) character2.x=event.x\*0.5

next after remove my character2, my last character have the position event.x

local character3=display.newImage(...) character3.x=event.x

and this is where i can’t find the way

i must make this to have my character who execute again a special transition with the tap

character3.x=character1.x

so it"s mean that i must inform

character1.x=event.x

and it"s impossible because character is outside of my function transitionSpecial

object:addEventListener( “tap”, special )

how can i do to inform a value below a local declaration ? to resume this

local value=x and next event.x function \> event.x local value2=event.x

If I understand this correctly, you want to start a transition, and then use the position of the object being transitioned to create another object when it is finished, right ?

I *think* that transition.to passes the object to its onComplete method so when you write something like 

transition.to(someObject,{time = 1000, x = 250, onComplete = function(obj) end })

then obj in the function refers to the object that is being transitioned, so you can get its new function and use that to spawn another object. 

Sorry, i am really a newbie…could you explain me with the code? i don’t see how to write the function(obj) ?

local rect=display.newRect(100,100,100,100) local function trans()   transition.to(rect, {200,200, yScale=0.5, xScale=0.5, onComplete=function(obj) end}) end trans()

function someFunction(obj) … and someFunction = function(obj) are the same - when you complete a transition it passes as a parameter the object that you have transitioned.

Example  - creates two circles , uses transition to move one down the screen. When that transition is complete its position is copied to the other circle, which is then transitioned somewhere else.

-- two circles, one red, one green. local circle1 = display.newCircle(40,40,40) circle1:setFillColor(1,0,0) local circle2 = display.newCircle(210,40,40) circle2:setFillColor(0,1,0) -- transition circle 1 down the screen a bit transition.to(circle1, { time = 1000, y = 300, -- when the transition completes, run this function. onComplete = function(obj) -- here, obj refers to circle1, so copy its position circle2 circle2.x = obj.x circle2.y = obj.y -- now transition circle2 somewhere else transition.to(circle2, { time = 1000, x = 300, y = 100}) end })

thank you for taking the time to answer me. I learned one more thing!
However I can not figure out what I’d like to do well.
I click on a part of the screen, my character goes up this point by making a jump (done in two transitions)
I put the entire code below by replacing all my images by forms if you want to test and I notice that my xmiddle is negative while
zero the display starts well at the top left?

If you could shed some light my lantern on my mistake it would be nice :slight_smile:
thank you and good day.

local background=display.newRect( 0,200,4000,4000 ) local character = display.newCircle( 0,0,30 ) character.fill.effect = "filter.blur" local paint = {1, 0, 0} character.fill=paint local xbegin = 0 local ybegin = 200 character.yScale = 0.5 character.xScale = 0.5 character.x = xbegin character.y = ybegin print( xbegin, ybegin ) local function myTapListener(event)                   if event.x==xbegin                 then                 local xmiddle=event.x                 else                 local xmiddle=(event.x-xbegin)\*0.5+xbegin                 end                 if event.y==ybegin                 then                 local ymiddle=event.y                 else                 local ymiddle=(ybegin-event.y)\*0.5+ybegin                 end                 print( xmiddle, ymiddle )                 print( event.x, event.y )                 local xend = event.x                 local yend = event.y         local function removal1(character)                character:removeSelf()                 local character = nil                                         end                           local function removal2(character)                                                  local character = display.newCircle( 0,0,30 )                         character.fill.effect = "filter.blur"                         local paint = {1, 0, 0}                         character.fill=paint                         character.x = xmiddle                         character.y = ymiddle                         print (character.x)                         print( xend, yend )                         local xbegin = xend                         local ybegin = yend                         print( xbegin, ybegin, xend, yend )                         character:removeSelf()                         local character = nil                              local character = display.newCircle( 0,0,30 )                         character.fill.effect = "filter.blur"                         local paint = {1, 0, 0}                         character.fill=paint                         character.x = xbegin                         character.y = ybegin                         character.yScale = 0.5                         character.xScale = 0.5                         return xbegin, ybegin, xend, yend                     end                 local transitionspecial = transition.to( character, { time=500, x=xmiddle, y=ymiddle, yScale=1, xScale=1, onComplete=removal1, transition=easing.inBounce })         local transitionspecial2= transition.to( character, { time=550, x=xend, y=yend, yScale=0.5, xScale=0.5, transition=easing.outElastic, onComplete=removal2 })    return xbegin, ybegin, xend, yend end background:addEventListener("tap", myTapListener )

these code work to transition 1 to 2 but after i repeat the operation it’s crash.

It’s seems that the last character don’t want to keep the xbegin position…but i don’t know why…

local background=display.newRect( 0,200,4000,4000 ) local xbegin = 0 local ybegin = 200 local character = display.newCircle( 0,0,30 ) local paint = {1, 0, 0} character.fill=paint character.yScale = 0.5 character.xScale = 0.5 character.x = xbegin character.y = ybegin local function myTapListener(event)     local xend = event.x     local yend = event.y                                   if (xend == xbegin)                 then                 xmiddle = xend                 else                 xmiddle = (xend-xbegin)\*0.5+xbegin                   end                                     if (yend == ybegin)                   then                   local ymiddle = yend                   else                   ymiddle = (yend-ybegin)\*0.5+ybegin                                    end         local function removal1(character)                character:removeSelf()                 character = nil                 character = display.newCircle( 0,0,30 )                         paint = {1, 0, 0}                         character.fill=paint                         character.x = xmiddle                         character.y = ymiddle                                         end               local transitionspecial = transition.to(             character, { time=500, x=xmiddle, y=ymiddle,             yScale=1, xScale=1, onComplete=removal1,             transition=easing.inBounce })         local transitionspecial2= transition.to(             character, { time=550, x=xend, y=yend, yScale=0.5, xScale=0.5,             transition=easing.outElastic,             onComplete=function(obj)             character.x = obj.x             character.y = obj.y               end             })    end background:addEventListener("tap", myTapListener )

almost immediately my transition does not work fluidly

local background=display.newRect( 0,200,4000,4000 ) local xbegin = 0 local ybegin = 200 local character = display.newCircle( 0,0,30 ) local paint = {1, 0, 0} character.fill=paint character.yScale = 0.5 character.xScale = 0.5 character.x = xbegin character.y = ybegin local function myTapListener(event)     local xend = event.x     local yend = event.y                                   if (xend == xbegin)                 then                 xmiddle = xend                 else                 xmiddle = (xend-xbegin)\*0.5+xbegin                   end                                     if (yend == ybegin)                   then                   local ymiddle = yend                   else                   ymiddle = (yend-ybegin)\*0.5+ybegin                                    end  local function spawn()                 character = display.newCircle( 0,0,30 )                         paint = {1, 0, 0}                         character.fill=paint                         character.x = xmiddle                         character.y = ymiddle                         character.yScale = 0.5                         character.xScale = 0.5                 end           local function removal1(character)                character:removeSelf()                spawn()                      end               local transitionspecial = transition.to(             character, { time=500, x=xmiddle, y=ymiddle,             yScale=4, xScale=4, onComplete=removal1,             transition=easing.inBounce })         local transitionspecial2= transition.to(             character, { time=550, x=xend, y=yend, yScale=0.5, xScale=0.5,             transition=easing.outElastic,             onComplete=function(obj)             character.x = obj.x             character.y = obj.y               end             })    end background:addEventListener("tap", myTapListener )

 

If I understand this correctly, you want to start a transition, and then use the position of the object being transitioned to create another object when it is finished, right ?

I *think* that transition.to passes the object to its onComplete method so when you write something like 

transition.to(someObject,{time = 1000, x = 250, onComplete = function(obj) end })

then obj in the function refers to the object that is being transitioned, so you can get its new function and use that to spawn another object. 

Sorry, i am really a newbie…could you explain me with the code? i don’t see how to write the function(obj) ?

local rect=display.newRect(100,100,100,100) local function trans()   transition.to(rect, {200,200, yScale=0.5, xScale=0.5, onComplete=function(obj) end}) end trans()

function someFunction(obj) … and someFunction = function(obj) are the same - when you complete a transition it passes as a parameter the object that you have transitioned.

Example  - creates two circles , uses transition to move one down the screen. When that transition is complete its position is copied to the other circle, which is then transitioned somewhere else.

-- two circles, one red, one green. local circle1 = display.newCircle(40,40,40) circle1:setFillColor(1,0,0) local circle2 = display.newCircle(210,40,40) circle2:setFillColor(0,1,0) -- transition circle 1 down the screen a bit transition.to(circle1, { time = 1000, y = 300, -- when the transition completes, run this function. onComplete = function(obj) -- here, obj refers to circle1, so copy its position circle2 circle2.x = obj.x circle2.y = obj.y -- now transition circle2 somewhere else transition.to(circle2, { time = 1000, x = 300, y = 100}) end })

thank you for taking the time to answer me. I learned one more thing!
However I can not figure out what I’d like to do well.
I click on a part of the screen, my character goes up this point by making a jump (done in two transitions)
I put the entire code below by replacing all my images by forms if you want to test and I notice that my xmiddle is negative while
zero the display starts well at the top left?

If you could shed some light my lantern on my mistake it would be nice :slight_smile:
thank you and good day.

local background=display.newRect( 0,200,4000,4000 ) local character = display.newCircle( 0,0,30 ) character.fill.effect = "filter.blur" local paint = {1, 0, 0} character.fill=paint local xbegin = 0 local ybegin = 200 character.yScale = 0.5 character.xScale = 0.5 character.x = xbegin character.y = ybegin print( xbegin, ybegin ) local function myTapListener(event)                   if event.x==xbegin                 then                 local xmiddle=event.x                 else                 local xmiddle=(event.x-xbegin)\*0.5+xbegin                 end                 if event.y==ybegin                 then                 local ymiddle=event.y                 else                 local ymiddle=(ybegin-event.y)\*0.5+ybegin                 end                 print( xmiddle, ymiddle )                 print( event.x, event.y )                 local xend = event.x                 local yend = event.y         local function removal1(character)                character:removeSelf()                 local character = nil                                         end                           local function removal2(character)                                                  local character = display.newCircle( 0,0,30 )                         character.fill.effect = "filter.blur"                         local paint = {1, 0, 0}                         character.fill=paint                         character.x = xmiddle                         character.y = ymiddle                         print (character.x)                         print( xend, yend )                         local xbegin = xend                         local ybegin = yend                         print( xbegin, ybegin, xend, yend )                         character:removeSelf()                         local character = nil                              local character = display.newCircle( 0,0,30 )                         character.fill.effect = "filter.blur"                         local paint = {1, 0, 0}                         character.fill=paint                         character.x = xbegin                         character.y = ybegin                         character.yScale = 0.5                         character.xScale = 0.5                         return xbegin, ybegin, xend, yend                     end                 local transitionspecial = transition.to( character, { time=500, x=xmiddle, y=ymiddle, yScale=1, xScale=1, onComplete=removal1, transition=easing.inBounce })         local transitionspecial2= transition.to( character, { time=550, x=xend, y=yend, yScale=0.5, xScale=0.5, transition=easing.outElastic, onComplete=removal2 })    return xbegin, ybegin, xend, yend end background:addEventListener("tap", myTapListener )

these code work to transition 1 to 2 but after i repeat the operation it’s crash.

It’s seems that the last character don’t want to keep the xbegin position…but i don’t know why…

local background=display.newRect( 0,200,4000,4000 ) local xbegin = 0 local ybegin = 200 local character = display.newCircle( 0,0,30 ) local paint = {1, 0, 0} character.fill=paint character.yScale = 0.5 character.xScale = 0.5 character.x = xbegin character.y = ybegin local function myTapListener(event)     local xend = event.x     local yend = event.y                                   if (xend == xbegin)                 then                 xmiddle = xend                 else                 xmiddle = (xend-xbegin)\*0.5+xbegin                   end                                     if (yend == ybegin)                   then                   local ymiddle = yend                   else                   ymiddle = (yend-ybegin)\*0.5+ybegin                                    end         local function removal1(character)                character:removeSelf()                 character = nil                 character = display.newCircle( 0,0,30 )                         paint = {1, 0, 0}                         character.fill=paint                         character.x = xmiddle                         character.y = ymiddle                                         end               local transitionspecial = transition.to(             character, { time=500, x=xmiddle, y=ymiddle,             yScale=1, xScale=1, onComplete=removal1,             transition=easing.inBounce })         local transitionspecial2= transition.to(             character, { time=550, x=xend, y=yend, yScale=0.5, xScale=0.5,             transition=easing.outElastic,             onComplete=function(obj)             character.x = obj.x             character.y = obj.y               end             })    end background:addEventListener("tap", myTapListener )

almost immediately my transition does not work fluidly

local background=display.newRect( 0,200,4000,4000 ) local xbegin = 0 local ybegin = 200 local character = display.newCircle( 0,0,30 ) local paint = {1, 0, 0} character.fill=paint character.yScale = 0.5 character.xScale = 0.5 character.x = xbegin character.y = ybegin local function myTapListener(event)     local xend = event.x     local yend = event.y                                   if (xend == xbegin)                 then                 xmiddle = xend                 else                 xmiddle = (xend-xbegin)\*0.5+xbegin                   end                                     if (yend == ybegin)                   then                   local ymiddle = yend                   else                   ymiddle = (yend-ybegin)\*0.5+ybegin                                    end  local function spawn()                 character = display.newCircle( 0,0,30 )                         paint = {1, 0, 0}                         character.fill=paint                         character.x = xmiddle                         character.y = ymiddle                         character.yScale = 0.5                         character.xScale = 0.5                 end           local function removal1(character)                character:removeSelf()                spawn()                      end               local transitionspecial = transition.to(             character, { time=500, x=xmiddle, y=ymiddle,             yScale=4, xScale=4, onComplete=removal1,             transition=easing.inBounce })         local transitionspecial2= transition.to(             character, { time=550, x=xend, y=yend, yScale=0.5, xScale=0.5,             transition=easing.outElastic,             onComplete=function(obj)             character.x = obj.x             character.y = obj.y               end             })    end background:addEventListener("tap", myTapListener )