This site requires JavaScript, please enable it in your browser!
Greenfoot back
zombiedude789
zombiedude789 wrote ...

2013/4/18

Scrolling ground help?

zombiedude789 zombiedude789

2013/4/18

#
Hello, I have been designing a sort of continuous side scrolling game for a class project. In a nutshell the player must avoid oncoming obstacles by jumping over them. As of currently i have implemented the player which can move left, right, jump, and can stand on a ground class. I also made the background scroll continuously to give the illusion that the player is moving. However, I have run into a problem with the ground class. I would like to make the ground class scroll just like the background but with gaps in between the ground for the player to fall into. Unfortunately, I do not know how to make the ground scroll. Do I implement the ground class with my background scroll world or do I create an entirely new subclass? Thank You
danpost danpost

2013/4/18

#
If you mean, "Do I implement the ground class scrolling with my background scrolling, then certainly. As the background moves, move all the Ground object the same amount. If 'scrollAmt' was the number of pixels to scroll by each act method, then:
// with the world scroll background method or code
for (Object obj : getObjects(Ground.class))
{
    Ground ground = (Ground)obj;
    ground.setLocation(getX()+scrollAmt, getY());
}
You will have to add new ground into the world on the one side and remove it from the world on the other. It is best to use an unbounded world.
You need to login to post a reply.