I’ve got a map with four wall objects on it. You can see them in the image and (hopefully) the small dots that denotes the first point selected as outlined in the Tiled docs.
Working with Objects — Tiled 1.4.2 documentation (mapeditor.org)
When it renders the object layer in game though that first point of each object is rendered at tile coordinate 1,1. Is that expected behaviour? Do I have to render each object in context of world space individually?
Thanks.
Not sure if the image below makes that clearer or not! It’s where the four objects are rendering.
Not really any code to offer.
Loading the map
// Map
tiledMap = Content.Load<TiledMap>("LevelBasement");
tiledMapRenderer = new TiledMapRenderer(GraphicsDevice, tiledMap);
// Map Objects
objLayer = tiledMap.GetLayer<TiledMapObjectLayer>("Objects");
The code that tests the player is in the polygon.
float x = cameraPosition.X;
float y = cameraPosition.Y;
var polyObj = obj as TiledMapPolygonObject;
if(GameMain.ContainsPoint(polyObj.Points, new Vector2(x, y)))
{
if(obj.Type == "Wall")
strText += "Wall (" + obj.Name + "), ";
}
else
{
strText += "Not Wall, ";
}
…and draw.
// Draw Map
tiledMapRenderer.Draw(tiledMap.GetLayer("Ground"), camera.GetViewMatrix());
// Set source of sprite
spriteSource = new Rectangle(nSpriteX, nSpriteY, 41, 42);
// Set height of joystick
int nJoystickY = GraphicsDevice.Viewport.Height - 500;
// Draw Sprite
Game.spriteBatch.Begin();
Game.spriteBatch.Draw(spriteTexture,
spriteLocation,
spriteSource,
Color.White);
Game.spriteBatch.End();
tiledMapRenderer.Draw(tiledMap.GetLayer("Higher"), camera.GetViewMatrix());