*** Move object through screen coordinates ***

hi

i am trying to move an object around the screen

i have stored the screen x and y coordinates in a 2 arrays

people[i].xposition  and people[i].yposition

how can i change the following code to move the object around the screen

local point = display.newRect( 0, 0, 20, 20 )

local listener1 = function( obj )
    
    print( "Transition 1 completed on object: " … tostring( obj ) )
    
end

for i=1,550
do

transition.to( point, { time=500,  x=people[i].xposition, y=people[i].yposition, onComplete=listener1 } )

end

why do you have the “for” cicle??? you don’t need it in the “transition.to”

transition.to it will move an object from A to B in the time you define, you don’t need anything more:

local point = display.newRect( 0, 0, 20, 20 ) local destinationX=300 -- change this to your destination X local destinantionY=300 -- change this to your destination Y local listener1 = function( obj ) print( "Transition 1 completed on object: " .. tostring( obj ) ) end transition.to( point, { time=500, x=destinationX, y=destinantionY, onComplete=listener1 } )

I believe OP is trying to do each transition after the previous one… correct? In which case you need a delay:

local point = display.newRect(0, 0, 20, 20) local listener1 = function(obj) print("Transition completed on object: " .. tostring(obj)) end for i = 1, #people do transition.to(point, {time = 500, delay = 500 \* (i - 1), x = people[i].xposition, y = people[i].yposition, onComplete = listener1}) end

[EDIT]: This approach works, but it’s probably better to set something a little more complex up - call the next transition during the onComplete listener of each transition. That’ll assure that you don’t get a low framerate when you have a lot of ‘people’ elements.

  • Caleb

hi

yes im a trying to achieve the next transition after the previous one

im going to try your code caleb p

thankyou

hope this works

any other ideas or code i can use here people

thanks so much

hi

tried above code but it just gets stuck on the first transition, caleb

could somebody try this code out to get it going

thankyou so much

hi 

managed to get it going/working but doesnt seem very smooth between transitions

this is what is working so far

local point = display.newRect(700, 250, 20, 20)

local listener1 = function(obj)
  --print("Transition completed on object: " … tostring(obj))
end

for i = 1, #people do
  transition.to(point, {time = 10, delay = 10 * (i - 1), x = people[i].xposition, y = people[i].yposition, onComplete = listener1})
end

can somebody please help with getting smoother speed

thanks so much

your time is to low, beeing 1000 1s, moving an object in 0.001s will always give you not smoth transitions.

you can try to change too your fps in config.lua

more fps means smother transition (but it needs higher processor)

why do you have the “for” cicle??? you don’t need it in the “transition.to”

transition.to it will move an object from A to B in the time you define, you don’t need anything more:

local point = display.newRect( 0, 0, 20, 20 ) local destinationX=300 -- change this to your destination X local destinantionY=300 -- change this to your destination Y local listener1 = function( obj ) print( "Transition 1 completed on object: " .. tostring( obj ) ) end transition.to( point, { time=500, x=destinationX, y=destinantionY, onComplete=listener1 } )

I believe OP is trying to do each transition after the previous one… correct? In which case you need a delay:

local point = display.newRect(0, 0, 20, 20) local listener1 = function(obj) print("Transition completed on object: " .. tostring(obj)) end for i = 1, #people do transition.to(point, {time = 500, delay = 500 \* (i - 1), x = people[i].xposition, y = people[i].yposition, onComplete = listener1}) end

[EDIT]: This approach works, but it’s probably better to set something a little more complex up - call the next transition during the onComplete listener of each transition. That’ll assure that you don’t get a low framerate when you have a lot of ‘people’ elements.

  • Caleb

hi

yes im a trying to achieve the next transition after the previous one

im going to try your code caleb p

thankyou

hope this works

any other ideas or code i can use here people

thanks so much

hi

tried above code but it just gets stuck on the first transition, caleb

could somebody try this code out to get it going

thankyou so much

hi 

managed to get it going/working but doesnt seem very smooth between transitions

this is what is working so far

local point = display.newRect(700, 250, 20, 20)

local listener1 = function(obj)
  --print("Transition completed on object: " … tostring(obj))
end

for i = 1, #people do
  transition.to(point, {time = 10, delay = 10 * (i - 1), x = people[i].xposition, y = people[i].yposition, onComplete = listener1})
end

can somebody please help with getting smoother speed

thanks so much

your time is to low, beeing 1000 1s, moving an object in 0.001s will always give you not smoth transitions.

you can try to change too your fps in config.lua

more fps means smother transition (but it needs higher processor)