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

2014/2/27

Launching object

1
2
danpost danpost

2014/3/3

#
Well, it appears to move vertically. Well, what it is doing is relocation to a point vertically above where it started. If you want it to move gradually up the screen, then you need to use something like 'setLocation(getX(), getY()-1)' in the act method. You want to put it in an 'if' block because it does not move all the time. The condition is that Link has touched it. So you need a boolean field (in the Pear class) to track whether Link has touched it or not. Set the boolean within the canSee block.
cyclobs cyclobs

2014/3/3

#
You mean something like this?
public void up()
    {
        if (canSee(Link.class) )
        {
            setLocation(getX(), getY()-5);

        }
    }
Or can you give the right code?
danpost danpost

2014/3/3

#
cyclobs wrote...
You mean something like this? // code omitted //
I do not mean anything like that. I mean something like:
if (canSee(Link.class)) sawLink = true;
if (sawLink) move();
Something like that (but not exactly that.
You need to login to post a reply.
1
2