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

2021/1/13

Placing an actor by using another actor

Bambus Bambus

2021/1/13

#
is there a way to playce an actor by pressing an actor which is holding
if (Greenfoot.mouseClicked(this)){

}
I already saw the post from Lucius (https://www.greenfoot.org/topics/59309/0) but I didn't really understand how to place the new actor.
Roshan123 Roshan123

2021/1/13

#
if (Greenfoot.mouseClicked(this))
{
Objectt obj = new Objectt();
getWorld().addObject(obj, getX(), getY());
}
Bambus Bambus

2021/1/13

#
Roshan123 wrote...
if (Greenfoot.mouseClicked(this))
{
Objectt obj = new Objectt();
getWorld().addObject(obj, getX(), getY());
}
thank you :D So.. I have tried it and it works.. but somehow I can't remove the actor by using
getWorld().removeObject(obj);
. I wrote
Object obj = new Object();[
at the beginning of the green box (sorry.. I don't know what it is called )
danpost danpost

2021/1/13

#
Bambus wrote...
Roshan123 wrote...
if (Greenfoot.mouseClicked(this))
{
Objectt obj = new Objectt();
getWorld().addObject(obj, getX(), getY());
}
I can't remove the actor by using
getWorld().removeObject(obj);
I wrote
Object obj = new Object();
at the beginning of the green box (sorry.. I don't know what it is called )
Try removing line 3.
Bambus Bambus

2021/1/13

#
danpost wrote...
Bambus wrote...
Roshan123 wrote...
if (Greenfoot.mouseClicked(this))
{
Objectt obj = new Objectt();
getWorld().addObject(obj, getX(), getY());
}
Try removing line 3.
So I tried but then there is on the addObject and removeObject line an error (cannot find symbol - variable obj).
danpost danpost

2021/1/13

#
Bambus wrote...
So I tried but then there is on the addObject and removeObject line an error (cannot find symbol - variable obj).
Please show entire class.
Bambus Bambus

2021/1/13

#
nevermind.. I just got it. But thanks to you two :D
You need to login to post a reply.