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

2015/11/6

It keeps saying "illegal start of expression" PLEASE HELP!

lpiggott lpiggott

2015/11/6

#
import greenfoot.*; import java.util.List; public class JumpWorld extends World { private int xOffset = 0; private final static int SWIDTH = 400; private final static int SHEIGHT = 2400; private final static int WHEIGHT = 2400; private GreenfootImage bimg; /** * Constructor for objects of class JumpWorld. * */ public JumpWorld() { // vertical scrolling world super(SWIDTH, SHEIGHT, 1, false); bimg = new GreenfootImage("jumpingmgbkgr.jpg"); shiftWorld(0); prepare(); private void shiftWorld(int dx) { if( (xOffset + dx) <= 0 && (xOffset + dx) >= SHEIGHT - WHEIGHT) { xOffset = xOffset + dx; shiftWorldBackground(dx); shiftWorldActors(dx); } } private void shiftWorldBackground(int dx) { GreenfootImage bkgd = new GreenfootImage(SWIDTH, SHEIGHT); bkgd.drawImage(bimg, xOffset, 0); setBackground(bkgd); } private void shiftWorldActors(int dx) { List<ScrollingActor> saList = getObjects(ScrollingActor.class); for( ScrollingActor a : saList ) { a.setAbsoluteLocation(dx); } } } }
danpost danpost

2015/11/6

#
All your methods are coded within the constructor of the class (you have a misplaced closing squiggly bracket).
DogeOverlord DogeOverlord

2015/11/6

#
Should be:
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
44
45
46
47
import greenfoot.*;
import java.util.List;
 
public class JumpWorld extends World
{
    private int xOffset = 0;
    private final static int SWIDTH = 400;
    private final static int SHEIGHT = 2400;
    private final static int WHEIGHT = 2400;
    private GreenfootImage bimg;
 
    /**
     * Constructor for objects of class JumpWorld.
     *
     */
    public JumpWorld()
    {   
        // vertical scrolling world
        super(SWIDTH, SHEIGHT, 1, false);
        bimg = new GreenfootImage("jumpingmgbkgr.jpg");
        shiftWorld(0);
        prepare();
    }
 
        private void shiftWorld(int dx)
        {
            if( (xOffset + dx) <= 0 && (xOffset + dx) >= SHEIGHT - WHEIGHT) {
                xOffset = xOffset + dx;
                shiftWorldBackground(dx);
                shiftWorldActors(dx);
                }
        }
        private void shiftWorldBackground(int dx)
        {
            GreenfootImage bkgd = new GreenfootImage(SWIDTH, SHEIGHT);
            bkgd.drawImage(bimg, xOffset, 0);
            setBackground(bkgd);
        }
        private void shiftWorldActors(int dx)
        {
            List<ScrollingActor> saList =
                getObjects(ScrollingActor.class);
            for( ScrollingActor a : saList ) {
                a.setAbsoluteLocation(dx);
            }
      }
}
Also use the code button when posting code as it makes it much easier to read
You need to login to post a reply.