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

2014/4/18

Tile and Scale GreenfootImage ?

oxsinus oxsinus

2014/4/18

#
I am trying to create a simple classic Donkey Kong clone. I am trying to create the girders for it. Right now I created a simple GirderActor and I re-use it many times within the scenario - generic reusable. I set the size to 256 x 32 .. place it .. rotate it slightly .. and voila - works great and is quite efficient. Where I'm running into difficulty is when I start putting the finishing touches on it - specifically the actor image. Because the girders need to be a single actor in order for me to rotate it - I am needing the ability to scale and tile an image. So my 8x8 pixel image will scale to the height of the actor (32 pixels) and then tile itself to fill the entire 256 pixel length. When using the GreenfootImage class however, it seems to only scale the image to fill the entire actor - I don't see an option or way to use the image for an actor, with a tile behaviour. There is a method of GreenfootImage to return the BufferedImage called getAwtImage(). If I check the docs for Java's BufferedImage class I see methods such as getNumXTiles(), getNumYTiles(). The more I read into the docs however the more it looks like this isn't what I'm after - wondering if its more of a memory tile functionality. Can anyone point me in the right direction? If there is a simpler way to implement this then please enlighten me. Thanks
danpost danpost

2014/4/18

#
You would either have to: (1) create a full-sized image and use a double 'for' loop to draw the image at the appropriate locations (do the tiling yourself); or, (2) create a separate world of the size of full-sized image, set its background image to your image, and then get its background image (let the world object tile the image for you)
oxsinus oxsinus

2014/4/18

#
It is seeming as if I am going to have to do #1 - and then compute the rotations myself. As for #2 - not 100% sure what you mean.
danpost danpost

2014/4/18

#
oxsinus wrote...
As for #2 - not 100% sure what you mean.
I mean something like this:
World tiledWorld = new World(256, 32, 1){}; // create image sized world
tiledWorld.setBackground(pixelImage); // tile image on world background
GreenfootImage actorImage = tiledWorld.getBackground(); // get bg image
setImage(actorImage); // set image of actor
oxsinus oxsinus

2014/4/20

#
Oh - I suppose I just figured that the original image is loaded, and the GreenfootImage is the original + modifications - not that it is actually changed and retained. Will have to try that. That sounds like it may be a nice workaround.
You need to login to post a reply.