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

2018/7/26

scrolling world

1
2
mole2003 mole2003

2018/7/26

#
Hi all, I am trying to make the google chrome t rex game. However I cannot make it scroll. Here is the code:
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class MyWorld here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Background extends World
{
 
    public static final int WIDE = 1000;
    public static final int HIGH = 600;
    private Scroller scroller;
    public Background()
    {
        super(WIDE,HIGH,1,false);
        GreenfootImage image = newGreenfootImage("background.png");
        scroller = new Scroller(this,image);
    }
    public void act()
    {
        scroll();
        prepare();
    }
    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        Trex trex = new Trex();
        addObject(trex,126,491);
        trex.setLocation(126,482);
        trex.setLocation(122,485);
    }
    private void scroll()
    {
        int speed = 2;
        scroller.scroll(0,- speed);
    }
         
}
The error message is that it cannot find "Scroller". Please help
mole2003 mole2003

2018/7/26

#
This is from a scrolling tutorial by Danpost: http://www.greenfoot.org/scenarios/18226
danpost danpost

2018/7/26

#
mole2003 wrote...
The error message is that it cannot find "Scroller".
You should have a class called Scroller in the Other classes group (below the Actor classes group). Not enough information is given to help any further. I could only presume that lines 14 and 19 were the problem lines. It is always best not to paraphrase error messages, but give and complete and accurate quoting of it (copy/pasting preferred).
mole2003 mole2003

2018/7/26

#
error messages are cannot find symbol - class Scroller (line14) cannot find symbol - method newGreenfootImage(java.lang.String) (line18) cannot find symbol - class Stroller (line19
Super_Hippo Super_Hippo

2018/7/26

#
First and third error mean that you don't have Scroller class (danpost wrote that already). For the second one, you have to add a space between 'new' and 'GreenfootImage'.
mole2003 mole2003

2018/7/27

#
Thank you both, SEcondly, this code scrolls up. I want it to scroll across like this: ---->
mole2003 mole2003

2018/7/27

#
Also where is the Other Classes group it is not below the actor classes group
Super_Hippo Super_Hippo

2018/7/27

#
It appears automatically if you have a class which does not extend Actor or World including its subclasses. I guess you need to change swap the passed parameters in line 40. I don't know the method, but it is likely that the first one is the x-direction and the second one the y-direction.
1
scroller.scroll(speed, 0);
mole2003 mole2003

2018/7/28

#
how do I get a class that doesnot extend actor or world
neeraj neeraj

2018/7/28

#
uiaehdwadxyiahvdfvuidfhvudhsdvi buishvbo jbbbbbbbbbbuuuuuuuuuuuuuuuuuuuuuuuuuuuh ux huhoiu bjhyuf ftdfdgsv ghcjvgctyffj t7iguygjg 7utig dtyr6u futiiii.luuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusdddddddxtj67ur6u o5uyt7iwqfyusdhcvuidyghdvusouyfvhf8ie ab lGgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjxzmjyyyyyyyyyy
Super_Hippo Super_Hippo

2018/7/28

#
Just remove the "extends ..." part in the "public class…" line.
danpost danpost

2018/7/28

#
mole2003 wrote...
how do I get a class that doesnot extend actor or world
Or, from the menubar, use Edit>New Class... or just Ctrl-N (the shortcut)
mole2003 mole2003

2018/7/29

#
Now that I have done the Scroller code there is another problem: "cannot find symbol - method (int,int)". This appears again in the Scroller code. World Code (called background):
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class MyWorld here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Background extends World
{
 
    public static final int WIDE = 1000;
    public static final int HIGH = 600;
    private Scroller scroller;
    public Background()
    {
        super(WIDE,HIGH,1,false);
        GreenfootImage image = new GreenfootImage("background.png");
        scroller = new Scroller(this,image);
    }
    public void act()
    {
        scroll();
        prepare();
    }
    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        Trex trex = new Trex();
        addObject(trex,126,491);
        trex.setLocation(126,482);
        trex.setLocation(122,485);
    }
    private void scroll()
    {
        int speed = 2;
        scroller.scroll(speed, 0);
    }
         
}
Scroller code:
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
27
28
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class Scroller here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Scroller
{
 
    private Background world;
    private GreenfootImage scrolImage;
    private boolean unlimited;
    private int scrolledX, scrolledY;
    private int wide, high;
    public Scroller(Background viewBackground, GreenfootImage image)
    {
        world = viewBackground;
        scrollImage = image;
        if (image != null)
        {
            wide = image.getWidth();
            high = image.getHeight();
        }
        scroll(0,0);
    }
}
The scoller also has another error: "cannot find symbol - variable scollImage" any ideas?
danpost danpost

2018/7/29

#
You are missing the scroll method in your Scroller class. Also, it looks like you deleted an 'l' in line 13. You should have just copy/pasted the 172 lines of code given for the Scroller class at the link given in the description of the tutorial.
mole2003 mole2003

2018/7/29

#
all 172 lines of code? One of them is saying about an unlimited scrolling world and of them about a limited scrolling world.
There are more replies on the next page.
1
2