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

2016/5/17

Scaling an Image

ZacBuzzsaw ZacBuzzsaw

2016/5/17

#
I have a sprite class that's working just as I want it to, but the problem is that it takes up approximately 60% of the world. So naturally, I've tried scaling it. I've attached the code that I've tried thus far, which has been effective in other, similar scenarios. What is it I'm doing wrong?
//First method of rescaling: one GFI
GreenfootImage image = new GreenfootImage("filename.jpg");
image.scale(image.getHeight()-100,image.getWidth()-100);
this.setImage(image);

//Second method of rescaling: two GFIs, with one GFI assigned to the other
GreenfootImage sprite = new GreenfootImage("filename.jpg");
GreenfootImage image = new GreenfootImage(sprite);
image.scale(image.getHeight()-100,image.getWidth()-100);
this.setImage(image);
SPower SPower

2016/5/17

#
The code you posted doesn't seem to have any problems as far as I can tell, so I think the problem is somewhere else (also because of the fact that you said it has been effective in other scenarios). And just one little thing: you don't need to explicitly say this.setImage, you can just call setImage.
ZacBuzzsaw ZacBuzzsaw

2016/5/17

#
I've no longer a need for an answer. Turns out the image rescales when the run button is pressed. All's well!
davmac davmac

2016/5/17

#
Turns out the image rescales when the run button is pressed
That indicates you have the code in an act() method. You should instead put it in the constructor for the actor.
You need to login to post a reply.