我正在尝试使用 Fisica(JBox2D 的端口)和 Processing 3 制作一个滚动世界。这段代码几乎可以正常工作,它可以正确滚动等等,但是当我使用 进行this.player
跳转时this.player.addImpulse(0, -150)
,它在世界不滚动但它在滚动时工作跳跃高度大大降低。为什么会发生这种情况,以及做滚动背景的更好方法是什么?
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;
}
}
如果需要,我已将完整代码放在 GitHub 上。但是请注意,它很混乱,因为我只是将它从处理 IDE 移植到 Eclipse。
提前致谢。