Hi all,
Pretty strange problem here, I am reading in a TiledMap and parsing through the Layers then creating a Box2D box around the collision layers.
Problem is, it reads in the tiles fine and puts a box around them, but the 33rd box seems to just be ignored and then shifts every box infront of that along one.
It fits to the size of my camera fine but as I want the camera to be scrolling along the map this issues occurs. It seems to ignore everything 33rd tile.
http://imgur.com/64QAU0FHere's what it looks like.
Source code for reading in TiledMap:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| package com.adamdowson.sideflyer.level;
import com.badlogic.gdx.maps.tiled.TiledMap; import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; import com.badlogic.gdx.maps.tiled.TmxMapLoader; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.BodyDef; import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; import com.badlogic.gdx.physics.box2d.FixtureDef; import com.badlogic.gdx.physics.box2d.PolygonShape; import com.badlogic.gdx.physics.box2d.World;
public class LevelLoader { private World world; private TiledMap map; private TiledMapTileLayer collisionLayer; private int tileWidth, tileHeight; private String levelName; public LevelLoader(World world, String levelName) { this.world = world; this.levelName = levelName; map = loadMapFile(); loadTileLayers(); initTiles(); } private void initTiles() { for (int x = 0; x < tileWidth; x++) { for (int y = 0; y < tileHeight; y++) { if (collisionLayer.getCell(x, y) != null) { createCollisionTile(x, y); } } } } private void createCollisionTile(int xPos, int yPos) { System.out.println(xPos + ", " + yPos); Vector2 tileCentre = new Vector2((xPos / 32) + 0.5f, (yPos / 32) + 0.5f); BodyDef body = new BodyDef(); body.type = BodyType.StaticBody; body.position.set(xPos, yPos); Body tileBody = world.createBody(body); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.5f, tileCentre, 0); FixtureDef tileFixture = new FixtureDef(); tileFixture.shape = shape; tileBody.createFixture(tileFixture); } private void loadTileLayers() { collisionLayer = (TiledMapTileLayer) map.getLayers().get("coll"); tileWidth = collisionLayer.getWidth(); tileHeight = collisionLayer.getHeight(); } private TiledMap loadMapFile() { String levelDir = "level/" + levelName + ".tmx"; return new TmxMapLoader().load(levelDir); } public TiledMap getMap() { return map; } } |