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

2018/5/7

How to scale multiple images for an actor?

Aura_ Aura_

2018/5/7

#
I'm scaling the image of one of my actors by 5/2. The problem is, when I switch to other images using animation this scaling doesn't carry over. Currently, I'm using something along the lines of...
 getImage().scale(getImage().getWidth()*5/2,getImage().getHeight()*5/2); 
...in the constructor of the class. I think my issue is that it's a one-time thing in the constructor, but if I put it in the act method it's repeatedly executed. Can I make it so it's executed once, whenever an image is changed? Thank you!
jamesN616 jamesN616

2018/5/7

#
You could try conditioning whether to scale the image on a boolean, so it's able to be scaled, but won't do so unless you set the boolean to be whatever you want For example:
//set a boolean: scaled = false;

if(!scaled)
{
    //put your line to scale the image here;
    scaled = true;
}
set scaled to false whenever you're needing to scale the image
danpost danpost

2018/5/7

#
Please show the entire class code for context.
You need to login to post a reply.