我想制作一个2D侧滚动游戏,游戏世界/游戏舞台向左移动,即背景像Flappy Bird一样向左过渡。有什么想法吗?我如何能够自动循环一个背景演员对象,它的宽度和高度与舞台的正交相机相同?
这真的很简单。您所需要做的就是在Actor实例上使用moveBy(x,y)方法。
float xMovingDelta = 10;
float yMovingDelta = 10;
actor.moveBy(xMovingDelta, yMovingDelta);
// Make sure you call the moveBy() method in a loop eg. the render() method.
这是我过去游戏中的一个例子:它使用了一个Table实例,但它们都有moveBy()方法。
private void mMenuToDiffMenuAnimation() { // I call this method from the render() meth.
if(difficultyTable.getX() > (540 - 64)){
menuTable.moveBy(-30, 0);
difficultyTable.moveBy(-30, 0);
}else {
fromMMToDiffMenu = false;
/* When the table's xPos is greater than 540 -64 stop the animation.*/
}
}