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

2015/2/2

Scrolling Background

1
2
Jellyfish Jellyfish

2015/2/2

#
Hello I'm trying to create a game of exploration where the screen will scroll up, down, left, or right. Thanks guys!
danpost danpost

2015/2/2

#
Look at some scrolling engines to see what is involved and how to do it. Although there are many different types (some that scroll infinitely and some that are limited to a specific range; some that only scroll horizontally or vertically and some that scroll along both axes; some that scroll constantly and some that only scroll to keep a main actor in view), the way the scrolling itself is controlled is fairly standard.
Jellyfish Jellyfish

2015/2/8

#
have you made one I can look at? That would definitely help
danpost danpost

2015/2/8

#
I have several: * Timed Scrolling uses an infinite universal scrolling system with a repeating background image; * Scrolling SuperWorld has a supporting superclass for a limited horizontal, vertical or universal scroller; * Infinite Fixed Side-scroller has a supporting superclass for a horizontal scroller whose actors are maintained off screen; * Pushy Woman is a limited horizontal scroller in a gridded world (one with cells larger than one pixel); * Horiz/Vert/Univ Scroller has a supporting superclass for a limited horizontal, vertical or universal scroller; * Killer Bees has an infinite universal scrolling system built in; All of these listed either are downloadable or you can access the code within the running of the scenario itself.
danpost danpost

2015/2/9

#
I had noticed that I did not have any scrolling engines that provided continuous scrolling. So, I created a supporting superclass that provides this functionality to a world (with the capability of wrapping the background image of the world). The Easy Infinite Scroller Support Class demos the use of it.
Jellyfish Jellyfish

2015/3/14

#
in Scrolling SuperWorld, I used the code, and I want to make the method getWidth, and it doesn't come to me as to how to do it. So basically, if you could help me make the method getWidth(), that'd be great. Thanks!
danpost danpost

2015/3/14

#
What exactly do you want this 'getWidth' method to return? The World class already provides one that returns the width of the world window; and the SWorld already provides a 'getScrollingWidth' method that returns the width of the scrolling area.
Jellyfish Jellyfish

2015/3/15

#
Never mind sorry I fixed it, but I have a new problem. I am trying to put another long platform, but I can't seem to successfully place it, so my character can go a ways, then he will fall because there are places with no ground. Thanks for the help!
danpost danpost

2015/3/15

#
Placing the platforms next to each other should not be that difficult. The width of the image of one can be used to determine where to place the next. The following should create a run of platforms the stretch across the entire scrolling area (the y-coordinate, '380', can be adjusted to suit -- found 3 times in the code)
1
2
3
4
5
6
7
Platform platform = new Platform();
int platformWidth = platform.getImage().getWidth();
int x = getWidth()/2;
addObject(platform, x, 380);
while (getUnivX((x += platformWidth)) < getScrollingWidth()) addObject(new Platform(), x, 380);
x = getWidth()/2;
while (getUnivX((x -= platformWidth)) > 0) addObject(new Platform(), x, 380);
As an alternative (and to have less actors in your world), you can create one long platform by stringing the images together for one actor.
1
2
3
4
5
6
7
8
public Platform(int reps)
{
    GreenfootImage single = getImage();
    GreenfootImage multiple = new GreenfootImage(single.getWidth()*reps, single.getHeight());
    for (int i=0; i<multiple.getWidth(); i+=single.getWidth())
        multiple.drawImage(single, i, 0);
    setImage(multiple);
}
With this platform constructor, you can string multiple platform images together for a single actor. To fill the entire scrolling area:
1
2
3
int platformWidth = new Platform(1).getImage().getWidth();
int reps = 1+getScrollingWidth()/platformWidth;
addObject(new Platform(reps), getWidth()/2, 380);
Jellyfish Jellyfish

2015/3/15

#
This is my Platform code, but when I compile, it gives me an error that says: cannot find symbol - method getScrollingWidth() So here is the code for the platform class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class floortiles here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Platform extends Actor
{
    /**
     * Act - do whatever the floortiles wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Platform()
    {
        GreenfootImage road = new GreenfootImage("grass.png");
        GreenfootImage image = new GreenfootImage(1040, road.getHeight());
        int w=road.getWidth();
        for(int offset=0; offset<1040; offset+=w) image.drawImage(road, offset, 0);
        setImage(image);
        int platformWidth = new Platform().getImage().getWidth();
        int reps = 1+getScrollingWidth()/platformWidth;
        addObject(new Platform(reps), getWidth()/2, 380);
    }   
}
danpost danpost

2015/3/15

#
It looks like you tried bits and pieces of what I gave you and made a conglomerate out of them. If you are going to create one, and only one, platform from this class, then you can remove lines 22 through 24 and just add one 'addObject' statement in your world constructor, or 'prepare' method, to add a 'new Platform()' into the world. This object should be added at an x-coordinate of 'getWidth()/2', the exact center of the world, horizontally.
Ben&Sam Ben&Sam

2015/3/16

#
Call Yourself mr functions mait, what if bluehand was not getObese()
Ben&Sam Ben&Sam

2015/3/16

#
we are 2 swaggy fo dis ting blad imma be out o dis place
Hersov Hersov

2015/3/16

#
^^ Please ban these "banter men". I was genuinely interested in how to move the screen and these guys are not helping by poisoning our forums. @danpost and @Davmac, please ban them. Cheers in advance.
Ben&Sam Ben&Sam

2015/3/16

#
pls no we very sorry oer mousekeybored is borkonnn
There are more replies on the next page.
1
2