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

2018/5/5

Removing an object when it's being touch and once it reaches a certain size.

DMan2000 DMan2000

2018/5/5

#
Hi! So, I'm working on a psuedo 3d game where you have to fly through balloons, but I'm having trouble getting the plane to only pop the balloon once the balloons scale method reaches a certain point.
public void popBalloon()
   {
       if (isTouching(redBalloon.class) && redBalloon.class.scale(.5))
       {
           removeTouching(redBalloon.class);
        }
    }
Any suggestions?
danpost danpost

2018/5/5

#
(1) scale is a GreenfootImage object method -- not a Class method; (2) a Class object (redballoon.class, in this case) cannot be used to reference any specific object of the class (how could it possibly know which object of the type to use?); Instead of using isTouching, use getOneIntersectingObject so you can gain a reference to any touching redBalloon object:
redBalloon red = (redBalloon) getOneIntersectingObject(redBalloon.class);
if (red != null && red.getScale() >= .5)
{
    getWorld().removeObject(red);
}
I threw in the method call to getScale, not knowing how you retain the value.
You need to login to post a reply.