How do I to swap position with others sprite?

Get help using Construct 2

Post » Fri Jan 12, 2018 2:04 pm

Hello,
there is a way (or addon) to swap position of an object with other? I'm making a puzzle game and I need that pieces of puzzle, at star of game, change position with others to random. Any suggestions? Thanks
B
2
Posts: 6
Reputation: 164

Post » Fri Jan 12, 2018 6:24 pm

Message: kriand can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Hey BalthazarTheWizard,

Here is an example of how it can be implemented. I made it with C3 so please open it there. It should work for C2 as well.
I hope it will help you.

c3p-file: https://1drv.ms/u/s!Ap_-qxoGKbDccub_B5pnfUs2rSM
B
6
Posts: 30
Reputation: 504

Post » Sat Jan 13, 2018 11:57 am

Wow my friend, you have done an immense job!!
Thank you very much! I'll study it!
B
2
Posts: 6
Reputation: 164

Post » Sat Jan 13, 2018 6:30 pm

kriand wrote:Hey BalthazarTheWizard,

Here is an example of how it can be implemented. I made it with C3 so please open it there. It should work for C2 as well.
I hope it will help you.

c3p-file: https://1drv.ms/u/s!Ap_-qxoGKbDccub_B5pnfUs2rSM


Construct 2 won't even find the file when you try to open. Do you have a version of this for C2?
B
235
S
131
G
9
Posts: 158
Reputation: 23,667

Post » Sat Jan 13, 2018 6:55 pm

YoHoho wrote:Construct 2 won't even find the file when you try to open. Do you have a version of this for C2?


As I said, you have to use C3. I tried to say that the code, transferred to C2, works there as well. I do not have a capx.
B
6
Posts: 30
Reputation: 504

Post » Sat Jan 13, 2018 7:09 pm

It's just a matter of saving the position of one of the objects to some variables and then setting the position of the objects to the other.

global number tempx =0
global number tempy = 0

start of layout
--- set tempx to sprite.x
--- set tempy to sprite.y
--- sprite: set position to (sprite2.x, sprite2.y)
--- sprite2: set position to (tempx, tempy)


For the example of swapping pieces around, i'd assume they are all instances of the same object type.

global number tempx =0
global number tempy = 0
global number iid1=0
global number iid2=0

start of layout
repeat 100 times
--- set iid1 to int(random(sprite.count))
--- set iid2 to int(random(sprite.count))
------ pick sprite instance iid1
--------- set tempx to sprite.x
--------- set tempy to sprite.y
--------- sprite: set position to (sprite(iid2).x, sprite(iid2).y)
------ pick sprite instance iid1
--------- sprite2: set position to (tempx, tempy)
B
94
S
33
G
123
Posts: 5,450
Reputation: 78,463

Post » Sat Jan 13, 2018 7:10 pm

Thank you!
B
2
Posts: 6
Reputation: 164


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 32 guests