Hi, I'm making a side-scrolling platformer game and I'm having problems scrolling the screen as the character moves. I figured it would be easy to do, by using getWorld().getObjects() and a for loop to set the location of each object as the character moves, but its proving to be more difficult...
Below is the method I'm using to try and attempt this... I have a few ideas on what's wrong right now, but I could use a couple outside opinion on how to do this... I've seen other people do this in their code, but it looked much more complicated than I thought it should be. Also I don't want the screen to change when the character moves higher on the screen or lower, just left and right
public void scrollScreen(){
List<Actor> allObjects = getWorld().getObjects(Actor.class);
if(doOnce == 0){
if(this.getX() == 500){
screenCentered = "centered";
doOnce = 1;
}
}
if(screenCentered == "centered"){
if(this.getX() != 500){
for(int i = 0; i < allObjects.size(); i++){
if(this.getX() >= 501){
Actor object = allObjects.get(i);
object.setLocation(this.getX() - 1, this.getY());
//this.setLocation(500, this.getY());
}else if (this.getX() <= 499){
Actor object = allObjects.get(i);
object.setLocation(this.getX() + 1, this.getY());
//this.setLocation(500, this.getY());
}else{
}
}
}
}
}

