Using the Box 2D demo from the Coding Workshop I have successfully gotten Spineboy walking across the screen bumping into the boxes as he should. However as soon as I render my tilemap to the screen, spineboy is now just a bunch of white boxes where his body parts should be.
Loading Image
package uk.co.candelacomputing.herbert.helpers;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.physics.box2d.World;
public class TiledMapHelper {
private final float unitScale = 1 / 128f;
private OrthogonalTiledMapRenderer renderer;
private TiledMap map;
public TiledMapHelper(String maplocation, World world) {
map = new TmxMapLoader().load(maplocation);
renderer = new OrthogonalTiledMapRenderer(map, unitScale);
}
public void render(OrthographicCamera camera) {
renderer.setView(camera);
renderer.render();
}
}
Code from render method of gamescreen
@Override
public void render(float deltaTime) {
float delta = Gdx.graphics.getDeltaTime();
world.step(delta, 8, 3);
totalTime += delta;
camera.update();
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(camera.projection);
batch.setTransformMatrix(camera.view);
batch.begin();
map.render(camera);
sd.findAnimation("walk").apply(skel, totalTime, true);
root.setX(root.getX() + 5 * delta);
skel.updateWorldTransform();
skelrenderer.draw(batch, skel);
batch.end();
// Position each attachment body.
for (Slot slot : skel.getSlots()) {
if (!(slot.getAttachment() instanceof Box2dAttachment)) continue;
Box2dAttachment attachment = (Box2dAttachment)slot.getAttachment();
if (attachment.body == null) continue;
attachment.body.setTransform(slot.getBone().getWorldX(), slot.getBone().getWorldY(), slot.getBone().getWorldRotation()
* MathUtils.degRad);
}
box2dRenderer.render(world, camera.combined);
}
Code seems fairly straight forward, seems like a bug since spineboy renders fine as soon as i comment out the map.render(); line (tho no map of course).