How do I check for a certain tile at any given position

0 favourites
  • 5 posts
From the Asset Store
Piano tiles
$9.99 USD
Template for a piano tiles game, fully documented in comments and video
  • I'm building a level editor, and right now I'm trying to use tilemaps for both terrain tiles and objects (like boxes). I would like to check when the level is tested for box tiles anywhere in the level (by tile id), delete the tile, and replace it with a sprite object instead (so I could make it interactive). If it works properly, I could probably use that method for things like coins, collectibles, doors and stuff.

    Also, would it maybe be better to use sprites instead of tilemaps for objects? I just considered that maybe I could maybe assign customizable properties to things like enemies and boxes (properties like health or loot or timers, idk).

  • Quick follow up, one of my events breaks when I leave the initial screen of the layout and move around the camera. I have an event set up so when I click the tilemap in an editor window (separate layer, paralax 0,0), but it selects tile id -1 instead of the tile I clicked on. I'm assuming it's not translating the mouse coordinates to the editor tilemap because of the parallax (the tilemap technically isn't moving). I think this because if I move my camera into the top left corner, I can click on the tiles and select them properly. Is there a way to fix this? mouse position and absolute position both result in the same thing.

  • TileMap object has a number of expressions to convert tile coordinates to screen coordinates and vice-versa.

    PositionToTileX(x)

    PositionToTileY(y)

    SnapX(x)

    SnapY(y)

    TileToPositionX(x)

    TileToPositionY(y)

    Use TileAt(x,y) to get tile ID.

    As for your second question, it depends on your game. If this is just for storing customizable properties for individual tiles, I would probably use an array or dictionary. If you need to add animations, behaviors etc. to your tiles, you will need to replace them with sprites. (or put sprites on top of them)

    I have an event set up so when I click the tilemap in an editor window (separate layer, paralax 0,0), but it selects tile id -1 instead of the tile I clicked on. I'm assuming it's not translating the mouse coordinates to the editor tilemap because of the parallax (the tilemap technically isn't moving)..

    Not sure I understand.. You may need to add scrollx, scrolly to your mouse coordinates. And probably subtract WindowWidth/2, WindowHeight/2. It's hard to tell without seeing your capx.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • TileMap object has a number of expressions to convert tile coordinates to screen coordinates and vice-versa.

    PositionToTileX(x)

    PositionToTileY(y)

    SnapX(x)

    SnapY(y)

    TileToPositionX(x)

    TileToPositionY(y)

    Use TileAt(x,y) to get tile ID.

    As for your second question, it depends on your game. If this is just for storing customizable properties for individual tiles, I would probably use an array or dictionary. If you need to add animations, behaviors etc. to your tiles, you will need to replace them with sprites. (or put sprites on top of them)

    > I have an event set up so when I click the tilemap in an editor window (separate layer, paralax 0,0), but it selects tile id -1 instead of the tile I clicked on. I'm assuming it's not translating the mouse coordinates to the editor tilemap because of the parallax (the tilemap technically isn't moving)..

    >

    Not sure I understand.. You may need to add scrollx, scrolly to your mouse coordinates. And probably subtract WindowWidth/2, WindowHeight/2. It's hard to tell without seeing your capx.

    Sorry I'm late, it's been a long week. Anyhow, here is what I'm using to select tiles and place them.

    tile selector is the tileset the user clicks to choose which block they are placing down. world 1 is the tileset where the user draws the level. the tile selector is on layer 5, which has a parallax of 0,0 (so it remains on screen while the user scrolls around the layout).

  • Try Mouse.X(layer) and Mouse.Y(layer)

    Return the position of the mouse cursor in game co-ordinates, with scrolling, scaling and rotation taken in to account for the given layer. The layer can be identified either by a string of its name or its zero-based index

    See also this post:

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