different objects with transition.to

suppose there is an obj say crate

crate=display.newImage(crate.png) 

crate.x=display.contentWidth/2;

crate.y=display.contentHeight/2;

local function moveRight(event)

         transition.to(crate,{time=2000,x=display.contentCenterX/2+200,onComplete=moveleft});

end

local function moveleft(event)

          transition.to(crate,{time=2000,x=display.contentCenterX/2+200,onComplete=moveleft}); 

end

moveRight();

suppose there are 10 other objects each require a different transition.to function with oncomplete parameter then how can we do it instead of creating similar function like above for each object? also is there any other way of calling this function when we use scenes instead of writing moveRight().

Please edit your post and fix the code formatting   <>. That is illegible.

You can do something like this:

local function move1(object) transition.to(object, object.transition1) end local function move2(object) transition.to(object, object.transition2) end local function newCrate(transition1, transition2) local crate=display.newImage(crate.png) crate.x, crate.y = transition1.x, transition1.y crate.transition1 = transition1 crate transition2 = transition2 transition1.onComplete = move2 transition2.onComplete = move1 return crate end local crate = newCrate({time=2000,x=display.contentCenterX/2+200}, {time=2000,x=display.contentCenterX/2+200}) move1(crate)

Like that you only have to call “newCrate” with the transition parameters for this object and call “move1(object)” with the create object as the parameter.

Greetings

Torben :slight_smile:

I’d rather use enterFrame with a function that handles all the 10 crates.

Please edit your post and fix the code formatting   <>. That is illegible.

You can do something like this:

local function move1(object) transition.to(object, object.transition1) end local function move2(object) transition.to(object, object.transition2) end local function newCrate(transition1, transition2) local crate=display.newImage(crate.png) crate.x, crate.y = transition1.x, transition1.y crate.transition1 = transition1 crate transition2 = transition2 transition1.onComplete = move2 transition2.onComplete = move1 return crate end local crate = newCrate({time=2000,x=display.contentCenterX/2+200}, {time=2000,x=display.contentCenterX/2+200}) move1(crate)

Like that you only have to call “newCrate” with the transition parameters for this object and call “move1(object)” with the create object as the parameter.

Greetings

Torben :slight_smile:

I’d rather use enterFrame with a function that handles all the 10 crates.