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

2019/4/19

Scaling the object's height not working

NoobFected NoobFected

2019/4/19

#
So I am trying to scale this object called "Mushroom" whenever it collides with the laser class. I am trying to make the Mushroom's height scale by 3/4. However, when I click the run button, I get this error: java.lang.IllegalArgumentException: Width (25) and height (0) cannot be <= 0 How do I fix this? The height is an instance variable set as 25 in the Mushroom() function. Here is the code for the function:
private void laserCollision(){
     Actor laser = getOneIntersectingObject(Laser.class);
     if (laser != null){
         GreenfootImage image = getImage();
         image.scale(width, height * (3/4));
     }
 }
danpost danpost

2019/4/19

#
NoobFected wrote...
How do I fix this? The height is an instance variable set as 25 in the Mushroom() function. Here is the code for the function: << Code Omitted >>
Remove the parentheses around the '3/4'. With them, it is evaluated first, as an int, which rounds down to 0.
NoobFected NoobFected

2019/4/19

#
thank you
You need to login to post a reply.