I'm trying to make a scrolling world with Fisica (port of JBox2D) and Processing 3. This code almost works, it scrolls correctly etc., but when I make this.player
jump with this.player.addImpulse(0, -150)
, it works when the world is not scrolling but when it is the jump height is greatly reduced. Why is this happening, and what is a better way of doing a scrolling background?
public void xOffsetCalculations() {
if (player.getX() > width - (width / 3)) {
float off = width - (width / 3) - this.player.getX();
this.player.setPosition(width - (width / 3), this.player.getY());
this.offset.x += off;
}
if (player.getX() < width / 5) {
float off = width / 5 - this.player.getX();
this.player.setPosition(width / 5, this.player.getY());
this.offset.x += off;
}
}
void yOffsetCalculations() {
if (player.getY() < height / 4) {
float off = height / 4 - this.player.getY();
this.player.setPosition(this.player.getX(), height / 4);
this.offset.y += off;
}
if (player.getY() > height - (height / 4)) {
float off = height - (height / 4) - this.player.getY();
this.player.setPosition(this.player.getX(), height - (height / 4));
this.offset.y += off;
}
}
I have put the full code on GitHub if it is needed. Be warned though, it is messy as I have only just ported it from the processing IDE to Eclipse.
Thanks in advance.