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

2019/12/6

step on actor and another one need to disappear

svenfrijters svenfrijters

2019/12/6

#
I'm trying to make a game where My player (olifant) steps on actor (knop) and if he steps on it; actor(knop) and actor(door) need to dissapear. I can make actor(knop) disappear but not actor(door).
public void act() 
    {
        hitByolifant();
        // Add your action code here.
    }    
        public void hitByolifant()
    {
        Actor olifant = getOneIntersectingObject(olifant.class);//Ik link nu de Projectile.class met de zombie.
        if(olifant !=null)//Als er een Projectile de zombie raakt, dan verliest de Zombie hp, en verwijdert greenfoot de Projectile.
        {
            getWorld().removeObject(this);
            getWorld().removeObject(door);
        }
        
    }
It gives me an error at removeObject(door); 'cannot find symbol - variable door' Can somebody please write a code where i can make both dissapear? I'm working for like hours now
svenfrijters svenfrijters

2019/12/6

#
this code is from actor(knop) btw :)
danpost danpost

2019/12/6

#
The removeObject method requires an Actor object to be removed. It will not accept a class name. If you have only one door in your world, you could use the following to remove it:
getWorld().removeObjects(getWorld().getObjects(door.class));
This will need to done before removing the knop object from the world as getWorld will return a null value otherwise.
danpost danpost

2019/12/6

#
svenfrijters wrote...
this code is from actor(knop) btw :)
I figured that out, already. Thx
svenfrijters svenfrijters

2019/12/6

#
at greenfoot.core.Simulation.run(Simulation.java:183) java.lang.NullPointerException at knop.hitByolifant(knop.java:26) at knop.act(knop.java:17) at greenfoot.core.Simulation.a this is what i get if i try it.
    public void hitByolifant()
    {
        Actor olifant = getOneIntersectingObject(olifant.class);//Ik link nu de Projectile.class met de zombie.
        if(olifant !=null)//Als er een Projectile de zombie raakt, dan verliest de Zombie hp, en verwijdert greenfoot de Projectile.
        {
            getWorld().removeObject(this);
            getWorld().removeObjects(getWorld().getObjects(door.class));
        }
        
    }
i did this with my code
svenfrijters svenfrijters

2019/12/6

#
ohh im stupid i needed to switch line 6 and 7
svenfrijters svenfrijters

2019/12/6

#
thx a lot
You need to login to post a reply.