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/29

#
never mind works. However all stationary sprites are leaving thier images behind infinitely.
danpost danpost

2018/7/29

#
mole2003 wrote...
never mind works. However all stationary sprites are leaving thier images behind infinitely.
The tutorial lets you know how do deal with them.
mole2003 mole2003

2018/7/30

#
where?
mole2003 mole2003

2018/7/30

#
also a jumping code for an actor doesnot work
danpost danpost

2018/7/30

#
mole2003 wrote...
where?
Main page, second paragraph.
also a jumping code for an actor doesnot work
That is independent of scolling and should be in a new discussion thread with relevant code.
mole2003 mole2003

2018/7/31

#
The code doesnot work the actor still leaves behind an infinite sat of images behind
danpost danpost

2018/7/31

#
mole2003 wrote...
The code doesnot work the actor still leaves behind an infinite sat of images behind
Show code of an actor exhibiting this behavior. Also, check to see if you can drag an image after pausing the scenario and report back the result.
mole2003 mole2003

2018/8/1

#
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.*;
  
public class Trex extends Actor
{
    private int ySpeed;
  
    public Trex()
    {
    }
    public void setLoaction(int x, int y)
    {}
    public void act()
    {
        int groundLevel = 500 - getImage().getHeight()/2;
        boolean onGround = (getY() == groundLevel);
        if (!onGround)
        {
            ySpeed++;
            setLocation(getX(), getY()+ySpeed);
            if (getY()>=groundLevel)
            {
                setLocation(getX(), groundLevel);
                Greenfoot.getKey();
           }
        }
        else // on ground
        {
            if ("up".equals(Greenfoot.getKey()))
            {
                ySpeed = -16;
                setLocation(getX(), getY()+ySpeed);
            }
        }
        if (Greenfoot.isKeyDown("down"))
        {
            setImage("duck.png");
        }
        else
        {
            setImage("Trex.png");
        }
    }
}
I can drag imagean
mole2003 mole2003

2018/8/1

#
image
danpost danpost

2018/8/1

#
mole2003 wrote...
code << Code Omitted >> I can drag image
If you have multiple images and the actor cannot move (because of lines 10 and 11), then it must be that you are creating multiple actors of this type. Where are you creating them? Show all class codes which contain:
1
... new Trex() ...
Super_Hippo Super_Hippo

2018/8/1

#
The method name is 'setLoaction' and not 'setLocation' though... not sure if this was intended.
danpost danpost

2018/8/2

#
Super_Hippo wrote...
The method name is 'setLoaction' and not 'setLocation' though... not sure if this was intended.
I overlooked that -- and yes, it should be setLocation.
mole2003 mole2003

2018/8/2

#
Thanks all
You need to login to post a reply.
1
2