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

2013/3/27

How to make the backround scroll

1
2
JetLennit JetLennit

2013/3/27

#
I am working on a game (that i haven't yet put out) that i need to make the background scroll. help would be appreciated.
danpost danpost

2013/3/27

#
I have several examples (and superclasses) that can be used to either look at or use for a scrolling background. Is it to be a side-scroller or a universal-scroller? are you creating the background as new area comes into view or is it a fixed limited background area? are you using pixel-sized cell or larger?
JetLennit JetLennit

2013/3/27

#
it is a game where you are always running and jumping over dumpsters and ducking under poles... and i want it to look like your running instead of their coming after you
danpost danpost

2013/3/27

#
So you want an infinite side-scroller that only moves to the right (the background moves left and your main character appears to move right). Correct? Will the background only scroll when the player is moved or will be background be continuously moving to the left and the player will be constantly (appearing to be) moving forward?
JetLennit JetLennit

2013/3/27

#
percicely
danpost danpost

2013/3/27

#
I added an additional set of questions to my last post.
JetLennit JetLennit

2013/3/27

#
the second one. you have no choice but to move, the only choice you have is to jump or duck
JetLennit JetLennit

2013/3/27

#
If needed i could post the current game so the code could be seen
danpost danpost

2013/3/27

#
Have the world act method move all objects in the world left by one; and in the main character act method have the main character move right by one. The combined effect will have everything but the main character move left. Use an unbounded world, using super(int, int, int, false). Add new object randomly off the right side of the world and have the object removed when they are off the left side a little bit (at least by the width of the object on both sides). Oh, if you have control objects in the world (things like counter, scores, buttons, etc.), have them move right by one in their act methods as well.
JetLennit JetLennit

2013/3/27

#
I that wasnt quite what i mean.... sorry about that. this is what i have so far.. i just want the background to scroll left
JetLennit JetLennit

2013/3/27

#
^that wanst ^meant
danpost danpost

2013/3/27

#
Have downloaded and am looking at, but have other things to do now. Will get back to it later.
JetLennit JetLennit

2013/3/27

#
okay, thank you
danpost danpost

2013/3/28

#
Add the following method to your world class and call it from the world 'act' method:
private void scrollBackground()
{
    GreenfootImage bg = new GreenfootImage(getBackground());
    getBackground().drawImage(bg, -1, 0);
    getBackground().drawImage(bg, getWidth()-11, 0);
}
I subtracted eleven from the world width because of the size of the image used for the background along with the size of each brick in that image. The image is one pixel short of four bricks wide with each brick being twenty-seven pixels wide. 107*5 (5 images) + 54(2 bricks) = 589 (11 short of the width of your world). It may not be the exact place to draw the image, but it is real cloase and it will scroll as long as we are consistent.
JetLennit JetLennit

2013/3/28

#
i have changed the code for the background a bit... but i can implement.. that into what i currently have thank you sooo much for helping!
There are more replies on the next page.
1
2