This site requires JavaScript, please enable it in your browser!
Greenfoot back
^v<>
^v<> wrote ...

2015/3/22

Having trouble with setImage

^v<> ^v<>

2015/3/22

#
I'm making a tower defense game and have an actor called towerRange which (as you might expect) is a circle indicating the range of the selected tower. It changes size depending upon what tower is selected, and all these size changes are severely pixelating it over time since I have to keep scaling it based on its previous size. I tried to fix this by setting its image to the image file each time before scaling, but the line doesn't seem to be having any effect. Could anyone tell me why and maybe recommend a fix? All of the below is inside the act method.
Terrain1 world = (Terrain1)getWorld();
        GreenfootImage image = getImage();
        if(image.getWidth() != world.rangeSize * 2){ /*basically, if the actor's size needs to change to fit the range of the newly selected tower; if it needs to be resized */
            setImage("Tower Range.png"); /*<--- the line that doesn't seem to be registering*/
            image.scale(world.rangeSize * 2, world.rangeSize * 2);
            setImage(image);
        }
davmac davmac

2015/3/22

#
You have these lines in succession:
            setImage("Tower Range.png"); /*<--- the line that doesn't seem to be registering*/
            image.scale(world.rangeSize * 2, world.rangeSize * 2);
            setImage(image);
Let me spell them out as pseudo-code:
  • set the image to "Tower Range.png"
  • scale the original image
  • set the image to the scaled version of the original
See the problem?
^v<> ^v<>

2015/3/22

#
setImage("Tower Range.png");
            image = getImage();
            image.scale(world.rangeSize * 2, world.rangeSize * 2);
            setImage(image);
yeah I knew it'd be something that simple :P thanks man
You need to login to post a reply.