How do I Switch positions of two sprites

0 favourites
  • 14 posts
From the Asset Store
Toggles Dials Switches and Alerts ! A foundational sound grouping of Analog type switches and Steampunk effects
  • Hello, here`s the thing:

    I am creating a inventory system that is its own layout and I am storing object data such as armor etc. in to instance variables of the sprite. Item creation (transferring collected items from actual level via Web storage) is working fine and the correct values are transferred.

    Inventory system works like this: you click object and then you click item slot and item moves to that slot. This also works fine.

    My problem is this: I can`t figure out how to switch two instances of the same sprite in to each other's positions.

    So i need to have it working like:

    Click Item1 in inventory slot 2

    Click item2(same sprite but different instance) in inventory slot 4

    Item1 snaps to inventory slot 4 & item 2 snaps to inventory slot 2.

    I tried to attach Capx but it kept saying that uploaded file is empty...

    Thanks in advance

  • This thread had a similar situation, manipulating two instances of the same object.

  • Thanks for your reply Blackhornet, double family thingy looks like it might work. I have to try it when I have little more time and little less tired brains. <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

    Also here`s the Capx via Dropbox if someone wants to take a look.

    https://dl.dropboxusercontent.com/u/137 ... ample.capx

    Thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Guys, store each object's position on an array (or global variables).Then you are good to go.

    If you try to swap positions wont work because when you move one of them the other will be out of position already.

  • Scofano, thanks for reply I see what you mean. However can you be little more specific how to achieve this, like how to pick instances vie events etc. I get the idea but I am having really hard time creating events for it.. Anyway thanks for your help

  • About arrays.

    https://www.scirra.com/manual/108/array

    Store each buttons position, then check the array for positions and make the switch.

  • You don't need an array, just two Temp variables.

  • blackhornet I think you are using the latest beta. I´m with the stable version, cannot open your file. I hope Virpoja can.

  • Scofano just a simple trick, rename the file to .zip instead of .capx, open it and edit the .caproj file tag " <saved-with-version>17300</saved-with-version>" to ***000.

    *** being whatever version you have

  • The original was 174, I checked.

  • caiorosisca Thanks for the tip, bro. <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    blackhornet sure, 174. But latest stable is 173. Isnt´t it? 174 must be beta.

    https://www.scirra.com/construct2/relea ... 3/download

  • blackhornet, I checked out your example. It`s still not working however... I made couple of tweaks since code you added was pointing to wrong object i think (it moved the item slot instead of the item). But i did n`t get it to work after that either. I think the solution you are offering will work it just needs a way to select the correct instances for the position switch (correct instances of Item1 sprite, that is). Well it`ll work eventually , thanks for your help so far guys.

  • You need to cache the last picked item, so you can work with both at the same time.

  • blackhornet, You Sir are Awesome!!

    Thanks a lot, now it`s working like a charm

    Thanks to everyone else too, once again Scirra community pulls through

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