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

2013/6/30

using same image different image sizes

davemib123 davemib123

2013/6/30

#
Hi, I have a class called Coin and I want to use 2 differnt sizes. The first size set is as a collectable item, the second size is for the HUD. I have this, which I am using right now:
public class Coin extends Mover
{
    private final GreenfootImage Coin1 = new GreenfootImage("coin-1.gif");
    private final GreenfootImage Coin2 = new GreenfootImage("coin-2.gif");
    private final GreenfootImage Coin3 = new GreenfootImage("coin-3.gif");
    
    public Coin()
    {
         setImage(Coin1);
         Coin1.scale(25,35);
         Coin2.scale(25,35);
         Coin3.scale(25,35);
    }
How would I go about using a different size for the HUD but still using the same class?
You could have another set of images that are bigger, and then add a constructor with a boolean. If it's true, it's in the world, and false is the other way around. And then you can determine which pictures to use from the boolean in the constructor.
davemib123 davemib123

2013/6/30

#
could you elaborate, i'm still a newb programmer :)
Gevater_Tod4711 Gevater_Tod4711

2013/6/30

#
Why do you want to use the class coin in your hud? For your hud you just need the image of the coin and the coin doesn't have to do anything. So it would be much easyer just to use the image.
davemib123 davemib123

2013/6/30

#
Good suggestion Gevater_Tod4711.
You need to login to post a reply.