How do I Change the tiels of one instance of a tilemap?

0 favourites
  • 5 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
  • I have a Tilemap class. I have two instances of it at runtime. At a point in my game I want to change all the tiles in only one instance of the tilemap. How is that possible? Currently there seems only to be the option to refer to the class of the tilemap when setting the tiles (using set tile).

    Is it possible?

    Thanks

  • If I understand correctly, you want to manipulate only a single tile or section of tiles at a time, within the entire tilemap, correct? Kind of like a digging thing example?

    If so, then yes it is possible.

    Lets say we want a tile to go away when we click it or touch it. Touch, btw, is used for most of these type of actions due to the option to use for mouse clicks btw. So let us use touch.

    In the event, set up a first event that points to the area or interest of tiles from another object, such as cursor, or player position etc. Its always best to reference something in the game on the layer of interest before applying the actions.

    This is done by using the "Pick nearest/furthest" system function.

    In the "Which" select nearest, then X and Y will be the area of the tilemap you want to focus on.

    So, the code would be something like:

    Tilemap.TileToPositionX(and the object mentioned above i.e. cursor.X, or player.X for examples)

    Do the same for Y, changing all Xs to Ys.

    Then in a sub event, you can reference the tilemap now.

    So, you say then that you want to use the when touched something (there are different functions for touch...test which works for you), and the action for that event (touch event), you can go to your Tilemap object, then there will be an option to erase tile range.

    If you want to only erase, for example, where you touch, as a single tile, you can:

    Erase Tile Range(Tilemap.PositionToTileX(Touch.X), and same for Y.

    Might have to find the exact codes, but these X and Y references should work just find.

    To make it more than one tile, change the tile range in the action, and even you can replace them, instead of erase, etc.

    Say you are making a tank, for example, and want destructible terrain. The bullet object would the the object of interest in the first event, instead of the tank, because you would want to explode the tiles at the bullet collision obviously. :)

    Hope that helps a bit!

    I'd post pics, but I haven't fully tested this yet.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Oh, and I read that twice again. For the entire tilemap of only two tilemaps, you can have the first event not point to anything but the instance UID of the tilemap instead of another object in the game. You should be able to use the same actions regardless as the action is specific to Tilemap object. Hope that makes sense!

  • There are lots of ways to pick an instance of Timemap object.

    If you know their UIDs, you can pick by UID. You can pick top or bottom instance, Nth in the order of creation etc..

    A popular method is to add an instance variable ID, set ID=1 to the first tilemap, ID=2 to the second tilemap instance and then simply pick one with the required ID:

    Tilemap compare instance variable ID=2 -> Set tile ....

  • There are lots of ways to pick an instance of Timemap object.

    If you know their UIDs, you can pick by UID. You can pick top or bottom instance, Nth in the order of creation etc..

    A popular method is to add an instance variable ID, set ID=1 to the first tilemap, ID=2 to the second tilemap instance and then simply pick one with the required ID:

    Tilemap compare instance variable ID=2 -> Set tile ....

    Great point for this....said above. You CAN add IDs to the properties of these independant of UID, like a variable kind of. That way you can order them based on numeric value very easily. Then point to that :) Great follow up info!

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