I would like to make a 2D Side-scroller game, where the game world/game stage is moving to the left, i.e. The background is transitioning to the left like Flappy Bird. Any ideas how I am able to automatically loop a background Actor object which has the same width and height as the Stage's Orthographic camera?
1 Answers
0
votes
Well it is really simple. All you need to do is use the moveBy(x, y) method on the Actor instance.
float xMovingDelta = 10;
float yMovingDelta = 10;
actor.moveBy(xMovingDelta, yMovingDelta);
// Make sure you call the moveBy() method in a loop eg. the render() method.
Here is an example from my past game: It uses a Table instance but they both have the moveBy() method.
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.*/
}
}