How do I to swap position with others sprite?

0 favourites
  • 7 posts
From the Asset Store
Full game Construct 2 capx code source to post on Google Play
  • 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

  • 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: 1drv.ms/u/s!Ap_-qxoGKbDccub_B5pnfUs2rSM

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Wow my friend, you have done an immense job!!

    Thank you very much! I'll study it!

  • 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?

  • 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.

  • 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)

  • Thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)