Moving an image to location of another image



Hi. I have two images of marbles. A blue marble called b1 and a yellow marble called y1. When b1 is clicked, I want it to move to the location of y1. It seems easy, but I apparently haven’t got the syntax right. What syntax should I be using? I’m currently referring to [[y1.x]] and [[y1.y]]. Do I need to load these values into variables or can I address the x and y coordinates directly?



Yes. The easiest way to do this is to set some local variables to reference the yellow marble widget:

You could also try playing around with the [[Target]] variable (ex. [[Target.x]]) but I’ve never had consistent luck with it.


This is easy to do, onClick of the blue marble - you reference the yellow marble as your target and use move TO [[This.left]] on x and [[]] on y, I added a bounce transition and gave it a one second time. (no need for local vars) You could move it back with an onClick of the yellow marble - but you would want to check it’s x position first to see if it has already moved. Attaching an rp file with example.

move_marbles.rp (42.5 KB)


Here is a version where you can click to move left, then click the yellow marble and move it back again. You would only need to decide how much you want to move it by. In this example, local vars are used in the condition statement.

Hope this helps

move_marbles-2.rp (43.3 KB)


Thanks for the helpful responses and the code samples (especially since I said I wanted to move b1 to b1 instead of y1), but you got the idea! It sounds like I’ll need to use variables if I’m referencing a different widget from the one that’s getting the click. I was hoping I could just directly reference the coordinates of the other widget.