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

2012/11/18

Remove life

Sl3nDeRm4n Sl3nDeRm4n

2012/11/18

#
Hello, heres my problem: i have 3 actor classes. when one object of class a hits an object of class b all objects of class b should be removed. how can i handle it? I created all object with a prepare method in a world-class loke this:
        A a1 = new A();
        addObject(new A(), 95, 89);
so how can i remove them with an actor?
SPower SPower

2012/11/18

#
Add this to the act method in the class a:
Actor b = getOneIntersectingObject(B.class);
if (b != null)
    getWorld().removeObjects(getWorld().getObjects(B.class));
Sl3nDeRm4n Sl3nDeRm4n

2012/11/18

#
yes but then i remove an object from class B if an Object of class A hits it. But iwant to remove Objects from class C
danpost danpost

2012/11/18

#
@Sl3nDeRm4n, you really need to be more specific as to what you are trying to accomplish. When A intersects B, what is supposed to happen (1) all instances of B are to be removed (2) only the instance that intersects A is to be removed (3) something else Same thing, when describing what you want when actor C is involved. (Remember, be specific.)
Sl3nDeRm4n Sl3nDeRm4n

2012/11/18

#
When A intersects B all instances of C are to be removed
SPower SPower

2012/11/18

#
Just do this in the act method in the A class:
Actor b = getOneIntersectingObject(B.class);
if (b != null)
    getWorld().removeObjects(getWorld().getObjects(C.class));
Sl3nDeRm4n Sl3nDeRm4n

2012/11/18

#
then it gives me an error which says: illegal start of type
SPower SPower

2012/11/18

#
Have you put it in your act method?:
public void act()
{
    // the code I gave you
}
Sl3nDeRm4n Sl3nDeRm4n

2012/11/18

#
yes i did
SPower SPower

2012/11/18

#
Can you show me all your code?
Sl3nDeRm4n Sl3nDeRm4n

2012/11/18

#
oh thx it worked was only typing fault
You need to login to post a reply.