Requesting a Pick Tile By # in Tilemap object

0 favourites
  • 8 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Yo, Scirra, I've been trying a number of different ways to go about this with tile maps, but I just can't find an efficient way to check to do it.

    Basically, what I want to be able to do is select a tile based on its number in the tilemap object itself. This condition would make making games using tilemaps a lot easier, as many games (such as the Pokemon Engine I'm making now) need to change a tile based on whether the player is touching it or not. And I can't seem to be able to check if the player isn't touching it. I can check if it is touching based on the player's position to tile position, but there is only the option to check if a tile exists at a position, not to test if a position exists at a tile... If that makes sense.

    What I'm asking is the option to do the opposite, for proper checking of individual tiles contacting another object.

    And I didn't know where else to post this, so I'm posting it in open topic.

  • Moved to Construct 2 General, as it is a more appropriate place for 'Discussion and feedback on Construct 2'.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If I understand the problem correctly, isn't it possible to do this with arrays? If you set the array size to be the same as the tilemap and whenever an object moves or is placed you update the array with the same x,y of the object on the tilemap. 0 for empty and 1 for occupied. Then you can check if a certain space is empty by referring to the array.

    I haven't tried it myself yet but it seems like something you could easily do with arrays.

  • If I understand the problem correctly, isn't it possible to do this with arrays? If you set the array size to be the same as the tilemap and whenever an object moves or is placed you update the array with the same x,y of the object on the tilemap. 0 for empty and 1 for occupied. Then you can check if a certain space is empty by referring to the array.

    I haven't tried it myself yet but it seems like something you could easily do with arrays.

    I've actually tried that, and it works of course. The only problem is that my computer is bad and has a problem with the loop I used to make it work. I was hoping that somehow another way could be implemented into the engine itself so that I would never have to use a loop to do it, but looping seems unavoidable.

  • Technically though, arrays wouldn't change a whole lot... Would it? I'm going to have to loop through positions in the array, or positions in the tilemap either way, in order to test it against the player's position. To be honest, I don't think using an array will do anything aside from adding an extra step, now that I think of it. The problem is performance. Where picking is instantaneous, and has almost zero hardware workload, and only has to be done once for each thing, because it points right to it, I'd have to loop through and compare each position. I can't think of a different way to use arrays for this kind of functionality..

  • I don't think you have to loop through the array, you can compare x,y values directly. Say you want to test the third tile south of the player you check the array like this:

    compare at XY

    -X: player.gridX

    -Y: player.gridY +3

    = 0

    then [do things]

    You can use tilemap.PositionToTile to get the object grid position but I usually create two variables where I store that info instead, makes it easier to work with, compare the above to:

    compare at XY

    -X: tilemap.positiontotileX(player.X)

    -Y: tilemap.positiontotileY(player.Y) +3

    = 0

    then [do things]

  • Actually picking is as efficient as looping over all the tiles, since each tile would need to be looked at to see if it should be picked. But like eliasfrost said you don't have to loop over all the tiles only the ones the player is overlapping.

    Link with examples to look at only overlapping tiles:

    Alternatively you could use just sprites instead of the tilemap to be able to do picking.

  • Oh wow... How did I not think about that? I feel like a moron, but thanks a lot eliasfrost (you too R0J0hound), comparing tiles based on a certain distance from the player would definitely work well, I appreciate the help!

    Oh and R0J0hound, I guess I didn't think about it, but picking would have to effectively do some sort of unseen loop, or else it wouldn't work. Thanks.

    My issue with looping or picking is that my tilemap is of about 3000 tiles, and looping through that at every tick is quite slooow. This solution is very nice. Thanks again, eliasfrost!

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