Reputation: 8190
Recently, I'm trying to learn AndEngine GLES2-Anchor
to create simple game in Android. I'm working with TiledMap and with example provided by Nicolas, I can load successfully my TiledMap and my "player" to screen. However, I want to know how to get a tile at specific position (example: at (260f,280f))? And if I can get that tile, how do I know that it contains a specific property or not (example property: "flower", "rose")? Can anyone know how to do it?
Upvotes: 1
Views: 481
Reputation: 12527
If you look at the TMXTiledMapExample you'll see that as the map loads it "counts cactuses". This is put there not because most people want to know how many cactuses there are, but to show that this is a great point in the code to store references to tiles and their properties for lookup during the game.
So as you parse your map, you can store references to the tiles created and lookup their properties as needed.
And as for knowing which tile it under a point its simple math. x = Column * tile width, y = Row * tile height.
An example using tiles that are 10x10. What tile is at 64,93? The tile at (Math.floor(64/tileWidth)), (Math.floor(93/tileHeight) or 6,9
If you store your tiles in a one-dimensional array instead of 2-dimensional, it the tile at rowIndex * rowsTotal + columnIndex
One final helping tip: be sure to get your row and column orders right. When debugging its easy to get them flip-flopped.
Upvotes: 1