Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am trying to add a sprite at a "grid" location on the tiled map. The TMX tiled Map is like a grid, and you can access the size of the grid by calling mTMXtiledMap.getTileRows() and mTMXtiledMap.getTileColumns().

I want to add an object at grid location, say (2, 5). My tileMap is of size (10,10).

How can I do that? There is no function like mTMXTiledMap.addChild(int x, int y, Entity mEntity).

I would appreciate any suggestions!

share|improve this question
    
Are you using "TileD" the map editor? If so then you should add an objects layer and add an object at the grid you want. Once you have done that you can use functions like 'getObject()' to return the position of the object. And then you can add whatever entity you like at the coordinates :) –  Savlon Mar 8 '13 at 20:13
    
Indeed I am using TileD as Map Editor. Adding an objects layer seems to be a good idea. You actually mean adding an object layer within TileD, right? And not something like tmx.addChild(objectLayer). Is that correct? –  shailenTJ Mar 11 '13 at 7:06
    
Yes I mean adding an objects layer in tiled –  Savlon Mar 14 '13 at 11:46

1 Answer 1

Just cheat:

Make a method that converts grid coordinates to scene coordinates and then place the sprite at the scene coordinates. I.e., just multiply the column by the tile width and the row by the tile height. Boom, you're done.

Sidenote: I'm assuming you want to add the sprite dynamically, as opposed to just changing the map, but yes, if you always want that sprite there, you should just add it to the map using Tiled as Savlon suggested.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.