How do I switch animation frames on 2 selected tiles?

Get help using Construct 2

Post » Fri Jul 22, 2016 12:09 pm

Hi guys

I'm having trouble finding simple way to select 2 tiles (out of 5) and swap their animation frames.

Tile One's frame becomes Two's current frame - and Tile Two's frame becomes Tile One's.

Basically, this is to do a scramble puzzle. You have to select 2 tiles out of 5 until you reorganise them into the correct work.

So far I have 5 tiles in a family called "tiles" which has the variable "name". Each tile is titled 1-5.

Each tile is set to a frame from 1-26 (alphabet).

If anyone can help, that would be awesome :)

Thank you in advance!
B
45
S
22
G
9
Posts: 142
Reputation: 9,080

Post » Fri Jul 22, 2016 1:08 pm

Hello Ninjadoodle,

You only want to switch two tills after 'click'?
I have make a simple project for you ... https://www.dropbox.com/s/lq07ulqxfgvuo7h/template_switch_tillmap.capx?dl=0

In my opinion I think a shorter way is to use sprites and compare/switch there frames ...
B
5
S
1
Posts: 24
Reputation: 423

Post » Fri Jul 22, 2016 1:27 pm

Hi @Ninjadoodle

@BillAlex 's way to do it works great.
But, if you only want to change the tile's frame, not position, you can do this:

Add 4 global variables: SwapNumber1, SwapNumber2, TileName1, TileName2.
When you select a tile (sub event: if counter is 0) => Set SwapNumber1 to tile's UID, set TileName1 to tile's name, add 1 to counter
(sub event: if counter is 1) => Set SwapNumber2 to tile's UID, set TileName2 to tile's name.
(sub sub event: select tile by UID (SwapNumber1)=> set Self.Name to TileName2, set animation frame to Self.Name
sub sub event: select tile by UID (SwapNumber2)=> set Self.Name to TileName1, set animation frame to Self.Name, set counter to 0.

Hope this helps.
B
16
S
9
G
5
Posts: 74
Reputation: 4,120

Post » Fri Jul 22, 2016 1:56 pm

Ohh ... I think I have misunderstood Ninjadoodle. He what to change the whole tilemap with a other, right?

@SimoneT: I don't see an action for 'set animation frame' for a tilemap-object. Or I'm wrong .... ?
To change the whole tilemap only i can use 'load image from URL'. In this case I have handle the images from beginning over the file API to get the URL from the used image. Or I'm wrong again ... ? :?
B
5
S
1
Posts: 24
Reputation: 423

Post » Fri Jul 22, 2016 2:32 pm

@BillAlex
Nope, my bad!
I skimmed your capx too quickly. I misread tilemap.PositionToTileX/Y as set position of tilemap...

@Ninjadoodle
My way works if you are using sprites objects, and BillAlex's way works for tilemap objects.
B
16
S
9
G
5
Posts: 74
Reputation: 4,120

Post » Mon Jul 25, 2016 4:14 am

Hi guys

@BillAlex, @SimoneT - Thank you heaps for your help! Sorry my question was a little confusing. I should not have used the term tile, as I'm actually using sprites.

I still can't get this working tho - I have five letter sprites and trying to swap any two of them at a time. I've setup a 'family' called letters, and tried using the techniques from above, but no luck.

What I have is ...

On touched Family 'Letters' then add 1 to Counter

(sub-event) if Counter = 0 then set Name to Letters.Name, set Num to Letters.AnimationFrame

(sub-event) if Counter = 1 then set Name2 to Letters.Name, set Num2 to Letters.AnimationFrame

... what I'm struggling with is actually looping through the letters family and switching the frames.

Thanks again for your help!
B
45
S
22
G
9
Posts: 142
Reputation: 9,080

Post » Mon Jul 25, 2016 11:54 am

Hi guys

I figure it out! Not really sure what exactly I was doing wrong, but now it works :)

Thanks heaps for your help - you guys are awesome!
B
45
S
22
G
9
Posts: 142
Reputation: 9,080

Post » Tue Jul 26, 2016 6:31 am

Hi @Ninjadoodle,

I'm glad that you found it yourself. This is always the best way to learn programming ;)
But I'm also so. One has a problem and you can't solve it ...

I think the problem was that the order of your programm was not correct.

(sub-event) if Counter = 0 then set Name to Letters.Name, set Num to Letters.AnimationFrame
(sub-event) if Counter = 1 then set Name2 to Letters.Name, set Num2 to Letters.AnimationFrame


The exact running of your code, I do not know, but I have often in this order the problem that the previous event results in that BOTH are triggered.
That's why I now use more often the Else command :)
B
5
S
1
Posts: 24
Reputation: 423


Return to How do I....?

Who is online

Users browsing this forum: plinkie, ST314, Yahoo [Bot] and 28 guests