Swap 2 image sprite

Please help me.

  1. Problem: I have some Image Sprite in a canvas. I want to code when I drag 1 Image to another Image (use Collided) then 2 Image swap position together.
  2. Ex: Before drag: Img1 (x1,y1); Img(x2;y2)
    After drag: Img1(x2,y2); Img2(x1;y1)
  3. My code is no issue when I use the exact names of Img1 and Img2. But when I use “Any Img”, its doesn’t work. Because I have many Img.
    Thank for any help

Post a screenshot of your blocks.

1 Like

Maybe that extension.

One Simple example that i did


Thank you. I saw it before, but i think it cant use with image in canvas. So i will try. Thank. And can u show me how to add video to my post.

Here is my code only with 3 block. It works normally. But when I disable block " when image sprite drag" and enable blobk “when any image sprite drag”, it works abnormally. It normal when I drag img 1 from left to right ( 2 img swap positon). But when I drag Img1 form right to left then Img 2 take Img 1’s position, Img 1 take another position

Is this the effect you want to achieve?

Here are the blocks for that same app in the video.


Thank for your help. I know what you code. But when I code as you. It error. Why

This is my project. I want to code for some Img. hihi

@Italo When I change my code (just only one: Img1. Drag to Any Img. Drag, ít failure. When Img1 moves from left to right, it is ok. But when img1 move from right to left, it can move to Img2 position.

So you need the images to switch only horizontally?
And the sprites need to be always at the same distance between each other?

1/ Yes, I need the Img switch only Horizontally or only Vertically dependent on my choice.
2/ Yes, the same distance between each other.
3/ Two clips I sent you to show what I want.
4/ Thank you

This is what I understand you want:

1 Like

The thing that makes this a lot easier is that I only switch the images between the sprites, but the sprites are always 1, 2, 3. You will never have sprite 1 in the second or third place. Or Sprite 2 in the first or third place.
So, if you need to know what image is on the first sprite, you only need to get sprite1.image and that’s it. This way you avoid having to build a tracking procedure to remember where was each sprite moved.

1./ Yes. Thank you for your help. Long time no see, so I think you forgot me. Very happy. I am afraid to remind you of my post. I am making a mini-game with my problem. So when I finish, I will show you.
2./ If you have free time, can you help me. I make code: when you insert your mail, click send OTP, the app will send an Email from my email to your email a number OTP. I have a script on google (search in the internet). When I run thí app, it still calls app script done but you never get OTP from me. I think problem form google script. I check it and it showed 100% fail. when I click send OTP button, the “script run” will increase 1 but it fails. (I’m Vietnamese)