How do I swap 2 sprite images?

0 favourites
  • 6 posts
From the Asset Store
Full game Construct 2 capx code source to post on Google Play
  • If i have Sprite1 with a specific Image and Sprite2 with a specific image and want to swap their images. I know i will need a temp sprite to rotate them I'm just not sure of the Event Action code. I have tried with Load Image From URL or data URI but no success.

    Im new to construct2 so any help is appreciated.

  • If you set up a sprite sheet, and then just switch from one frame to another frame, that sounds like what you need. Am I understanding you correctly?

  • Unfortunately no.

    The sprites are going to be a deck of cards. So the easiest method is the Bubble sort.

    Temp1.image = Sprite1.image

    Sprite1.image = sprite2.image

    Sprite2.image= Temp1.image

    Each sprite will have 1 image and random #'s will swap them. There can be no doubles, so swap is the easiest to shuffle a deck.

    Loading 52 images per card then changing the Animation frame is overkill.

  • Perhaps someone with more experience with Construct 2 could chime in and tell me if there is a better way, but here's how I would do what you are describing ...

    I'd create one sprite and call it "Cards", and load one-and-only-one sprite sheet containing the entire deck (including any repeated cards). Then in the the Layout, I'd copy and paste the number of cards I plan on displaying at any given time (ie 5 cards for poker.) However, I'd only have one sprite in my objects, not 52.

    Then I would add an "Array" to the layout and call it "DeckOfCards". The array would have one index for each of the frames in the one sprite's sprite sheet. For example, an array of 52 numbers with values of 0-51. At first the cards would be in order, meaning the index 0 would contain 0 referring to frame 0.

    Next in the event sheet, I'd add a global number that I could call "temp" and then use it to help shuffle or sort the DeckOfCards Array. After sorting, I'd set the frames of the copies of the sprite "Cards" using their IID's or UID's.

    To keep track of dealt cards, I might have a second global number that tracked the index of the current top-of-deck.

    So for all the card manipulation, I'd use numbers referring to frames in the one-and-only-one sprite. Numbers are easy to manipulate and swap in Construct 2, so I think this would cause less headaches. I think that would fit the Construct 2 paradigm well, and be easier to handle than 52 (or whatever the deck size) of unique sprites would be.

    Hope that helps.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • terrancd has some good ideas. I've not done a card game, but one sprite containing all the card images and arrays for data management are definitely the way to go.

  • After a lot of experimenting it would seem i can't swap images between sprites and I'm assuming because they are framed animations and there is no image property as there is in Windows programming.

    You are right about how to handle the deck and shuffle. Im going to use an array with a depth of 2 so i have Frame, Suit and Value. Then use the old fashion bubble sort with the array instead. After the array is mixed up i can change each cards Frame according to the array then assign the depth values to their Instance variables.

    I appreciate your help and suggestions... I'm sure ill be back for more as i have just started my first app.

    Thanxs

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