I'm a begining game developer and I'v read that, to optimize the jar size of your application you should try putting several animation frames into one single png file, and then extract the individual frames, to avoid the overhead cause by the headers in each png file.
the problem is, I tried to do this, by loading the full image, and then painting a portion into a properly sized mutable image, and i can correctly extract the frames, only, since the blank mutable image is fully white, every transparent pixel in my image is now white, and every sprite in my game has a very ugly white rectangle around it, any ideas how to avoid this? i know its possible, i'v seen it done in other games, but I have no clue how.
I m also a new entry in this field, but I have wrked on this image file stuff.....From what u have written, are you sure your image is transparent... in fact, your question creates a confusion...
every sprite in my game has a very ugly white rectangle around it
this happens when your image FILE is not transparent and so if there is any circular image in your FILE(say)..and u draw it on the canvas, the rest of the spacew as defined by your lipping rectangle has some colour, as the orignal File was not transparent...
Joined: Nov 08, 2005
Thanks for your reply, I'm pretty sure my image is transparent, my problem is: I load the whole image (several frames) into an image object, then I paint a portion of that big image (one frame) into a blank, mutable Image object, the size of one frame, but since the blank image is filled with white pixels, my transparent pixels are now white.
I think maybe the clipping rectangle thing could help me, but I havn't been able to figure it out from the documentation, how do I use it?
I think when you crop/create a new immutable Image object that the transperancy gets lost. It was like I had this Image that was one size, and I wanted to resize it based on the devices screen size, so that it could fit. But in order to resize you have to create a new Image object and copy the original into it, and that will always loose the transparency of the original image.
then I paint a portion of that big image (one frame) into a blank, mutable Image object, the size of one frame, but since the blank image is filled with white pixels, my transparent pixels are now white.
See let me tell you the common way to do this stuff(as I normally do it)...
-->Either you use a canvas and directly paint on it...all of ur images(leave the clip rectangle thing for a while).... --->or u use a mutabale image and get its graphic context by using getGraphics()....
Now u have the graphic context( by either of the ways)....then u use clipRect
Now Suppose your "frame" in your file is at (Frame_x,Frame_y) and is of size = wdFrame*htFrame......... You set the clip Rectangle(the effective area in which next drawing will actually be visible)... of the same dimension(see in the code)....this implies whatever u draw on the screen next it will be EFFECTIVE only in that region(starting from (x,y) to (x+wdFrame,y+htFrame)....
Then you draw the image by Shifting the coordinates accordingly, so that your desired frame gets SHOWN......Now actually you have drawn image at (x-Frame_x, y-Frame_y), but it will be shown only in(x, y, wdFrame, htFrame)....AND if everything goes right you will be able to see your Frame...
BEST F LUCK...
By the way i m still not able to understand y u r u getting that bug... next time u copy that particular lines of ur code where u r doing this painting...
As per my view double buffering solve ur problem...
use getGraphics() and cliping...
A. G. Parekh
Joined: Sep 08, 2005
Hi Ashish, I m in confusion ...can double buffering solve the transparency issue?... coz if I m guessing it rightly then thats is what camilo is doing(or how can 1 draw an image on the mutable image...I mean without getting the graphic context using getGraphics()???....)
kindly throw some light on it...
Joined: Nov 08, 2005
As Ramender correctly guessed, I am using getGraphics on the mutable image and then painting on it for clipping, that is the source of my problems, I believe the answer might be in using the clipping rect, thanks a lot Ramender, I'll let you know how it went.
Joined: Nov 08, 2005
Hello Ramender, I tried what you said, and realized, that was exactly what I was doing before, here's the code:
I create a mutable image, the size of one frame(which is automatically initialized with white pixels) then I get its graphics, and i paint on it, offset by the frames coordinates, and still I get the white rectangle. The only thing I'm not trying is the cliprect, but i don't see how that would make a difference.
I also painted the entire image directly and it is transparent, it just loses all transparency after painting it on the smaller mutable image, and i cant use clip rect on the original image becase its inmutable, Im at a loss, please help.
Joined: Sep 08, 2005
Hi Camilo, First of all,we dont use clipRect() on the IMAGE, it is used to set an area on the SCREEN, where the drawing will take effect,
For example if you are using your current method and in paint, say following lines are there-->
Assume "source" is an immutable image of size "176 X 220"... If there is no clipRect statement there, the complete image will be shown, However, if we induce clipRect(), COMPLETE IMAGE appears to be drawn there, BUT, due to clipping restrictions, the ACTUAL change in the screen contents take effect only in the area specified by arguments of clipRect(), therefore only a small portion of the image is visible, which is ofcourse in the clipped rectangle... Play with clipRect for a while, just to get its working...
Now coming back to Image transparency,--> MUTABLE IMAGES ARE OPAQUE, clearly written in the documentation,...So I assume, we will have to implement it differently..
As far as, I am getting your function getFrame(), it appears to be used only for getting the individual frame......
If it is so.. 1. Dont use this function, i.e. dont use mutable image 2. Understand how clipRect() works...
Let me give you an example...
Lets assume that following lines are there in your code...
That code can be replaced by...
No transparency issue will be there in the new coding..
Read both the posts carefully, try this thing and lets hope it works
Thanks a lot for your help Ramy, I was obviously doing it wrong, I tried what you told me, painting the whole inmutable image directly into the stage, setting the clipRect for it, and it worked fine, I'm just a bit worried about performance now, because before i only had to do a drawImage and now i have to do two setClips besides the drawImage, and I'm also painting a bigger image each time, I hope it does't have too big an impact.