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

2017/6/15

click (part two)

Venbha Venbha

2017/6/15

#

OMG

ok now i know how that when you click you get a sound... but when we click in the background the object must move toward where we clicked... But I dont get the codee.. can some 1 please tell me _______ ( 0 0 ) ___________\___/
Super_Hippo Super_Hippo

2017/6/15

#
private int[] target = null;

public void act()
{
    if (Greenfoot.mousePressed(null))
    {
        MouseInfo m = Greenfoot.getMouseInfo();
        target[0] = m.getX();
        target[1] = m.getY();
    }
    
    if (target != null)
    {
        if (Math.sqrt(Math.pow(getX()-target[0], 2)+Math.pow(getY()-target[1], 2)) < 3) //close to target
        {
            target = null;
        }
        else
        {
            turnTowards(target[0], target[1]);
            move(2);
        }
    }
}
danpost danpost

2017/6/15

#
The 'target' array needs to be initialized before you can assign values to its elements. Insert at line 8:
target = new int[2];
Venbha Venbha

2017/6/21

#
I dont get it? where must Write it?? ->

world

->

Actor

->

(someting else?)

Venbha Venbha

2017/6/21

#
for now i will do it in:

ACTOR!!

Venbha Venbha

2017/6/21

#
and world>_<
Venbha Venbha

2017/6/21

#
IT IS NOT WORKING can some 1 send me a demo that is opened in greenfoot and created in that??PLEASSE
Venbha Venbha

2017/6/21

#
or send the link of it thx
danpost danpost

2017/6/21

#
Venbha wrote...
for now i will do it in: ACTOR!!
That would be appropriate since it is the actor that needs a target to move toward.
Venbha Venbha

2017/6/22

#
danpost wrote...
Venbha wrote...
for now i will do it in: ACTOR!!
That would be appropriate since it is the actor that needs a target to move toward.

but it is moving away from!!

Venbha Venbha

2017/6/22

#
oh i did one thing wrong let me correct it...i reaaly- ...Nothing.
You need to login to post a reply.