How do I swap 2 sprite images?

Get help using Construct 2

Post » Sun Jul 05, 2015 2:40 am

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.
B
3
Posts: 9
Reputation: 193

Post » Sun Jul 05, 2015 3:33 am

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?
B
29
S
16
G
23
Posts: 68
Reputation: 13,723

Post » Sun Jul 05, 2015 4:39 am

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.
B
3
Posts: 9
Reputation: 193

Post » Mon Jul 06, 2015 12:29 am

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.
B
29
S
16
G
23
Posts: 68
Reputation: 13,723

Post » Mon Jul 06, 2015 1:34 am

@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.
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,208
Reputation: 43,838

Post » Mon Jul 06, 2015 10:32 pm

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
B
3
Posts: 9
Reputation: 193


Return to How do I....?

Who is online

Users browsing this forum: David181, evillair and 59 guests