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

2013/1/3

Quick question

TheStop TheStop

2013/1/3

#
I have this code in my World1 class when fly class is gone the ball class should then be removed, I looked in the documentation of the world class and there is a method in the called removeObject so why does it now work? The error says removeObject cannot be applied to given type.
if (getObjects(Fly.class).size() == 0) {
removeObject(Ball.class);
}
erdelf erdelf

2013/1/3

#
removeObject removes an Object not a class. You need to put a reference to the object here
TheStop TheStop

2013/1/3

#
something like
Ball= Ball.class
and put
removeObject(Ball);
erdelf erdelf

2013/1/3

#
no, not really. something like
removeObjects(((Actor)getObjects(Ball.class).get(0)));
TheStop TheStop

2013/1/3

#
ok, thank you for your time.
TheStop TheStop

2013/1/4

#
I have one more question i was typing this code and it compiled fine (this is in the Fly class), but when the ball comes in contact with the fly nothing happens.
 public void Shot()
{ 
Actor Ball;
         Ball= getOneObjectAtOffset(0, 0, Ball.class);
        if ( Ball!= null)
        {
            World world;
            world = getWorld();
            world.removeObject(Ball);
    
     healthcounter.subtract(5);
}
} 
erdelf erdelf

2013/1/4

#
replace line 4 with this and it should work
Ball = getOneIntersectingObject(Ball.class);
You need to login to post a reply.