<CNMM22 Dynamic Original:
there is a GIF
I took care of it and got it on the Java, Direct G.draw is the effect:
This is the limit of treatment, because this picture is made for a white background, and my background is black.
But, in the end I made it out to be this effect:
You can see that I'm cooler: the color of the feathers blends perfectly, and the feathers are glowing with fluorescence.
And my feathers can change around, my feathers are fluttering, and my shells can change color!
How did I do that??
To achieve this effect, you cannot directly g.draw gif, because the GIF color deep problem, he can not show so perfect transparency effect.
I mean, if you don't need to make a fluorescent effect, you can make a GIF first, then draw directly in Java, it's important that when you do gif, you want to really do the background transparent, to avoid as we see above, for the white bottom to make a gif on the black bottom is not good, at this time, Pre-production of pictures is very important, be sure to communicate well with the artist first.
But in this way, you can only say goodbye to my perfect flood effect.
How did I do it? First I split each frame of the GIF animation, and each of them processed separately, processing including 1, magic wand to remove the background color, 2, replace with white-related background color is transparent color, 3, in fireworks under the effect of fluorescence, and finally save them to support the higher color depth of the PNG format. Of course you can do it under PS.
After completion:
Now I'm talking about something about Java drawing, which involves at least 2 points of knowledge:
First, the static introduction of the picture, I first make a static code block.
Where TK is static Toolkit tk = Toolkit.getdefaulttoolkit (); , this is the usual practice. Why use static blocks of code? Because they are in memory I just need to put a copy, and preferably preloaded.
I'm not using it in my last article.About AWT not practical third-party class library to achieve picture rotation, deformation and other processing Speaking of Mediatracker, so I used a piece of code to preload, to avoid the beginning of the game when the picture does not appear:
Public void Draw (Graphics g) {
if (!first) {for (int i = 0; i < imgs1.length; i++) {G.drawimage (Imgs1[i], -466, -466, NULL);}for (int i = 0; i < imgs.length; i++) {G.drawimage (Imgs[i], -466, -466, NULL);}
First = true;}
The role of this first can be seen.
OK, here's the point, how to display the picture. The focus is on transparency, and I'm only using two short pieces of code to do the core function:
Where the red code is transparent to the picture, you can copy and paste using:
((GRAPHICS2D) g). Setcomposite (Alphacomposite.getinstance (alphacomposite.src_atop, Alpha));G.drawimage (Imgs1[step], x-46, y-59, NULL);((GRAPHICS2D) g). Setcomposite (Alphacomposite.getinstance (alphacomposite.src_over));
This is preceded by a declaration: float alpha = 0.7f; Transparency
There are a few details to be aware of in order to make my cool animations, and I'll explain this here: first, see my code here is divided into two parts, to the direction of my barrel to draw my wings in different directions, is the outermost if.
Second, step++ the ability to play frames by frame for all animations.
But finally found that, so, the wings move too fast, animation is not supple, so join ii,ii=5, that every 5 frames per broadcast I move the wings, but the naked eye can not feel, the last to see is a smooth effect, here, ii to the value of your frame speed to decide, I am 5 OK, The key is to be able to think of such a process.
Finally, how does the discoloration of the shells be done?
I enlarged the shells and I could see
The outermost layer of the shell has a transparent red color, and the core is that you want to use such a transparent layer and save her in PNG format. When a lot of shells overlap, the effect comes out.
Well, combined with my last ripple "about AWT not practical third party class library to achieve picture rotation, deformation and other processing", I believe you have some confidence in the Java production of games and animation. Someone said, I have ccsprit why should I be so tired?? Of course I'm talking about Java now.
How to make perfect animations in Java (including transparency effects)