Requesting a Pick Tile By # in Tilemap object

Discussion and feedback on Construct 2

Post » Fri Nov 06, 2015 9:17 am

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. :P
ImageImage
B
46
S
13
G
2
Posts: 253
Reputation: 6,352

Post » Fri Nov 06, 2015 9:29 am

Moved to Construct 2 General, as it is a more appropriate place for 'Discussion and feedback on Construct 2'.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
84
Posts: 5,375
Reputation: 58,432

Post » Fri Nov 06, 2015 10:06 am

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.
B
20
S
8
G
4
Posts: 195
Reputation: 3,555

Post » Fri Nov 06, 2015 10:13 am

eliasfrost wrote: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. :P 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.
ImageImage
B
46
S
13
G
2
Posts: 253
Reputation: 6,352

Post » Fri Nov 06, 2015 10:17 am

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..
ImageImage
B
46
S
13
G
2
Posts: 253
Reputation: 6,352

Post » Fri Nov 06, 2015 10:45 am

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]
B
20
S
8
G
4
Posts: 195
Reputation: 3,555

Post » Fri Nov 06, 2015 5:44 pm

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:
how-do-i-destroy-irregular-shapes_p985413?#p985413

Alternatively you could use just sprites instead of the tilemap to be able to do picking.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Mon Nov 09, 2015 2:17 am

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!
ImageImage
B
46
S
13
G
2
Posts: 253
Reputation: 6,352


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 7 guests