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

2012/10/7

weird duplication?

-nic- -nic-

2012/10/7

#
im making a scenario, and the head of a turrret points towards the mouse but for some reason there are two turret heads take a look: http://www.greenfoot.org/scenarios/6071 and im not sure why please help thanks
erdelf erdelf

2012/10/7

#
not sure but I think that every act cycle you add a turret remove the act method of the world and make this to your button class:
import greenfoot.*;
public class Button extends Actor
{
    public void act() 
    {
        if(Greenfoot.mouseClicked(this))
        {
            getWorld().removeObject(this);
            this.setBackground("corkboard.jpg");
            Bar b = new Bar();
            addObject(b,400,10);
            Turretbase turretbase = new Turretbase();
            addObject(turretbase, 67, 556);
            TurretTop turretTop = new TurretTop();
            addObject(turretTop, 67, 530);
        }
    }    
}
-nic- -nic-

2012/10/7

#
thanks ill try it now
erdelf erdelf

2012/10/7

#
forgot that this is not the world, make a reference to the world everytime you call world methods like this:
import greenfoot.*;
public class Button extends Actor
{
    public void act() 
    {
        if(Greenfoot.mouseClicked(this))
        {
            getWorld().setBackground("corkboard.jpg");
            Bar b = new Bar();
            getWorld().addObject(b,400,10);
            Turretbase turretbase = new Turretbase();
            getWorld().addObject(turretbase, 67, 556);
            TurretTop turretTop = new TurretTop();
            getWorld().addObject(turretTop, 67, 530);
            getWorld().removeObject(this);
        }
    }    
}

-nic- -nic-

2012/10/7

#
dont worry i did it and added the referances and the getWorld().removeObject(this); had to go last in the statement or it throws a nullPointerExeption
-nic- -nic-

2012/10/7

#
thanks
You need to login to post a reply.