I'm working on a tile 2d-side platformer game. I have done some stuff so far. I'm working on a basic collision detection using rectangles of libgdx so considering I have only grass block for now I made a single block world in Java (file reader is not ready) the problem is my detection only works the first time in other words if I spawn my colliding to a block it detects collision and do so. Although if i spawn my player top of the block with out colliding player falls forever.
Here is the code world.update(); =>
public void update() {
Iterator<block> cb = Blocks.iterator();
while (cb.hasNext()) {
block b = cb.next();
if (b.getBounds().overlaps(player.getBounds())) {
if (player.getPosition().x >= b.getPosition().x + 32) {
//RIGHT
player.getVelocity().x = 0;
} else if (player.getPosition().x + 32 <= b.getPosition().x) {
//Left
player.getVelocity().x = 0;
}
//All Y
player.getVelocity().y = 0;
}
if (!b.getBounds().overlaps(player.getBounds())) {
player.getVelocity().y = -gravity;
}
}
}