How do I switch animation frames on 2 selected tiles?

0 favourites
  • 8 posts
From the Asset Store
Each tile 64 by 64 pixels - Ultimate Tile Set for your awesome games
  • 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!

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

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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 ... ?

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

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

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

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

    [quote:2uafqd5o](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

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