help on transition.to inside of a table.

I have an image. And I want that image to move from point A to point B.

I do that with transition.to and works perfect.

But now I have 5 images inside of a table and I use a “for” loop “do” to create the images

The images are there, but they are not moving, I’m doing something wrong.

This is the code

local quarterNoteTable = {}     local indexNote = 0         for row = 1, 5 do             --for column = 1, 2 do             indexNote = indexNote + 1         local quarterNoteUp = display.newImageRect("images/quarterNoteUp.png", 38, 101)             quarterNoteUp.x = (row \* 200) - 20             quarterNoteUp.y = 206             --whiteKey.y = column \* 104             quarterNoteTable[indexNote] = quarterNoteUp             group:insert ( quarterNoteTable[indexNote] )             --end             transition.to(quarterNoteUp[indexNote], {time=1000, x=(row \* 100) - 20, y=206})         end

Thanks for your help

Victor
 

Hi Victor,

Try changing

[lua]

transition.to(quarterNoteUp[indexNote], {time=1000, x=(row * 100) - 20, y=206})

[/lua]

to either

[lua]

transition.to(quarterNoteTable[indexNote], {time=1000, x=(row * 100) - 20, y=206})

[/lua]

or

[lua]

transition.to(quarterNoteUp, {time=1000, x=(row * 100) - 20, y=206})

[/lua]

Either one of these options should work.  (What you had wasn’t working, because you were indexing into the display object itself.)

  • Andrew

Thank you andrew.

So I need to index the table…

and not the display object

It worked. Thanks.

Let me ask you this…maybe you know.

The first image moves very little, and the second more and the fifth a lot.

it means the distance between the images are every time less and less, until the end all of them get to the same point.

Is there a way there I can keep the same distance apart from each object

and the move from point A to point B.

Let’s say 50 pixels apart, and they are always 50 px apart, but they transition to point B?

Victor

Hi Victor,

Sure, take a look at the ‘delta’ option in transition.to (http://docs.coronalabs.com/api/library/transition/to.html).  If you set that to true, then the values you specify for x,y will be interpreted as the changes rather than the final values.  If you give each object the same change, then the spacing between them will stay the same.

  • Andrew

Thank you Andrew, I don’t know how delta works, but it works!

I just add delta=true and that’s it, it works!

I’m putting the code here if other people see this they can learn

local quarterNoteTable = {}     local indexNote = 0         for row = 1, 8 do             --for column = 1, 2 do             indexNote = indexNote + 1             quarterNoteUp = display.newImageRect("images/quarterNoteUp.png", 38, 101)             quarterNoteUp.x = (row \* 500) + 200             quarterNoteUp.y = 206             --whiteKey.y = column \* 104             quarterNoteTable[indexNote] = quarterNoteUp             group:insert ( quarterNoteTable[indexNote] )             --end             transition.to(quarterNoteTable[indexNote], {time=20000, x=-5000, y=0, delta=true})         end

Thank you Andrew.

Hi Victor,

Try changing

[lua]

transition.to(quarterNoteUp[indexNote], {time=1000, x=(row * 100) - 20, y=206})

[/lua]

to either

[lua]

transition.to(quarterNoteTable[indexNote], {time=1000, x=(row * 100) - 20, y=206})

[/lua]

or

[lua]

transition.to(quarterNoteUp, {time=1000, x=(row * 100) - 20, y=206})

[/lua]

Either one of these options should work.  (What you had wasn’t working, because you were indexing into the display object itself.)

  • Andrew

Thank you andrew.

So I need to index the table…

and not the display object

It worked. Thanks.

Let me ask you this…maybe you know.

The first image moves very little, and the second more and the fifth a lot.

it means the distance between the images are every time less and less, until the end all of them get to the same point.

Is there a way there I can keep the same distance apart from each object

and the move from point A to point B.

Let’s say 50 pixels apart, and they are always 50 px apart, but they transition to point B?

Victor

Hi Victor,

Sure, take a look at the ‘delta’ option in transition.to (http://docs.coronalabs.com/api/library/transition/to.html).  If you set that to true, then the values you specify for x,y will be interpreted as the changes rather than the final values.  If you give each object the same change, then the spacing between them will stay the same.

  • Andrew

Thank you Andrew, I don’t know how delta works, but it works!

I just add delta=true and that’s it, it works!

I’m putting the code here if other people see this they can learn

local quarterNoteTable = {}     local indexNote = 0         for row = 1, 8 do             --for column = 1, 2 do             indexNote = indexNote + 1             quarterNoteUp = display.newImageRect("images/quarterNoteUp.png", 38, 101)             quarterNoteUp.x = (row \* 500) + 200             quarterNoteUp.y = 206             --whiteKey.y = column \* 104             quarterNoteTable[indexNote] = quarterNoteUp             group:insert ( quarterNoteTable[indexNote] )             --end             transition.to(quarterNoteTable[indexNote], {time=20000, x=-5000, y=0, delta=true})         end

Thank you Andrew.