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

2020/2/24

Switching and scaling sprite images in a Constructor

earnold earnold

2020/2/24

#
Hi Programmers, I am wondering what the best way to both switch and scale images in a constructor. I want to reduce the sizes of the sprites in code rather than in Photoshop or something similar. For instance, I know about making new object variables like... image1 = new GreenfootImage("sprite1.png"); image2 = new GreenfootImage("sprite2.png"); image3 = new GreenfootImage("sprite3.png"); setImage(image1); and I know about how to scale images using something like this... getImage().scale(getImage().getWidth()/3,getImage().getHeight()/3); and I know about calling a custom method to switch sprites, such as... public void switchImage() { if (getImage() == image1) { setImage(image2); } else { setImage(image1); }} However, I'd like to know the BEST way to keep all of the sprite images scaled or reduced down during a game. Thanks much!
danpost danpost

2020/2/24

#
earnold wrote...
what the best way to both switch and scale images in a constructor.
You would only set one image in the constructor -- never switch (although setting one will replace one, I would not call that switching).
I'd like to know the BEST way to keep all of the sprite images scaled or reduced down during a game.
Am I correct in saying you mean the following? "I'd like to know how to keep all of the sprite images scaled or reduced down during a game." Because whatever works along with everything else is good. Because there is not much to it, just scaling images in the constructor and using them elsewhere in your code, there is little room for BEST for keeping or scaling.
You need to login to post a reply.