Hi
Im trying make an event occur when an object is clicked on by the mouse so far I have put doesn't work.
public void act()
{
if(Greenfoot.mousePressed("button1"))
{
triger ();
}
}
public void triger()
{
{ Unarmed unarmed = new Unarmed();
getWorld().addObject(new Unarmed(), getX(), getY()+5);
getWorld().removeObject(this);
}
Thou if I chabge it to isKeyDown("space") it seems to work. Also If I have two events that occuer on space or mouse press should they occuer at the same time as in another class I have,
public void triger()
{
life--;
if(life==0)
{
placeDebris(getX(),getY(),NUM_FRAGMENTS);
getWorld().removeObject(this);
}
}
private void placeDebris(int x, int y, int NUM_FRAGMENTS)
{
for(int i = 0; i < NUM_FRAGMENTS; i++)
{
getWorld().addObject(new Debris(), x, y);
}
}
public void act()
{
if(Greenfoot.mousePressed("button1"))
{
triger();
}
// Add your action code here.
}
also this seems to work when the mouse pressed is changed to isKeyDown space thou it seems not to work on one space press. ie on first space press the first block of code on this page works and then on the second one works so does the next section of code as I was trying to intnate thes two objects at the same time.
Thanks in advance for your responce.