Side scrolling collision detection & mob rendering

Hello there,

I’m making a sidescrolling shooter game. When I added the sidescrolling functionality I stumbled upon LOTS of bugs. Collision detection was completely broke, and mob rendering was screwed up.

I don’t really understand what the problem is since the X keeps updating, and when you move out of the frame the X value should know you’re out of the frame… buuuuttt I keep getting things as these: (this is on a multiplayer server, notice the difference between the two frames)

So I tried to do


int renderingX = mob.getX() - translateX;
int renderingY = mob.getY() - translateY;

But that didn’t work out either.

Also, collision detection is broke… For some reason this function in the mob code would never return false anymore.


public boolean mayMove(int x, int y, Level level, LevelState state)
	{
		rect.setBounds(x + state.translateX, y + state.translateY, getResource().getImage().getWidth(null), getResource().getImage().getHeight(null));

		for (Tile tile : level.getTiles())
		{
			boolean touchingRight = tile.asRectangle().intersects(rect);
			boolean touchingLeft = tile.asRectangle().intersects(rect);
			boolean touchingDown = tile.asRectangle().intersects(rect);
			boolean touchingUp = tile.asRectangle().intersects(rect);

			if (direction == Direction.RIGHT && touchingRight && tile.isSolid())
			{
				return false;
			}
			if (direction == Direction.LEFT && touchingLeft && tile.isSolid())
			{
				return false;
			}
			if (direction == Direction.DOWN && touchingDown && tile.isSolid())
			{
				return false;
			}
			if (direction == Direction.UP && touchingUp && tile.isSolid())
			{
				return false;
			}
		}
}

I really need some help because I cant understand why this doesnt work.

Thanks in advance!