Page 1 of 1

need help with clones! swap positions.

PostPosted: Sun Mar 20, 2011 10:01 pm
by sonicfire
hi folks! :)

i really need help! i have 10 actors (clones!) on screen, all from one baseactor, called diamond.
they only differ in animations (red, blue, green and so on...).

now when i click one "diamond" (one clone), and then another, i want these two to swap / exchange positions on screen.
so basically diamond1 = diamond2 x and y and diamond2 = diamond1.x and y.

however i cannot get this to work. i tried something like this in mouse down event:
Code: Select all
Actor *a,*b;

a = getclone(diamond);
sourcex = a->x;
sourcey = a->y;


and within second mouseclick:
Code: Select all
b = getclone(diamond);
targetx = b->x;
targetx = b->y;
// swap positions
a->x = targetx;
a->y = targety;
b->x = sourcex;
b->y = sourcey;


the code is not complete here, it´s just to show what i´m trying to do and what i came up with so far.
however this doesnt work, the first diamond jumps to the "target" diamond , but this one doesnt jump back to where
i have first clicked :-(

can anybody help me to achieve this somehow? whats a good way to do it?

Re: need help with clones! swap positions.

PostPosted: Sun Mar 20, 2011 11:12 pm
by skydereign
Try this. I originally had just a global Actor*, but it had problems setting the actor's xy... so I just used getCloneIdx and had a variable diamondIdx.

Re: need help with clones! swap positions.

PostPosted: Sun Mar 20, 2011 11:35 pm
by sonicfire
absolutely amazing. have to learn from this. thank you so much! +1 :D

Re: need help with clones! swap positions.

PostPosted: Mon Mar 21, 2011 1:08 am
by Scorpion50o1
making a bejeweled kinda game i see?

Re: need help with clones! swap positions.

PostPosted: Mon Mar 21, 2011 1:49 pm
by sonicfire
trying to, yes :) but now i realize it is WAY harder than i thought :lol: