Take you into the game development of the world game frame animation processing
<ignore_js_op>
1. The principle of frame animation
Frame animation frame animation as the name implies, a frame of a frame animation is a frame animation. Frame animation and our childhood to see the principle of the cartoon is the same, in the same area to quickly switch pictures to show people a visual illusion feel like in the play animation, in fact, is just n pictures in a frame of the switch.
: The implementation of the character walking animation, 4-frame walking animation in the playing area, a frame to the left to play to give people an illusion of playing the animation, the picture is moving, very simple, the other three direction to play the animation method similar to I no longer one by one example.
<ignore_js_op>
2. Original files for animation resources
Original file for animation resources PNG generally has three forms of presentation please listen to me.
1. Each frame is a PNG image
Up and down the direction of each group of animation each frame is a PNG picture, play animation need to switch the entire picture, to achieve animation effect. The code only need to complete the next frame of the picture to cover the previous frame of the picture is OK, this arrangement of resources in the program algorithm is the simplest.
<ignore_js_op>
2. All animation frames are present in a PNG image
A PNG contains all of the characters of the frame animation, play the animation when the program needs to calculate the image to be played in the original image of the starting and ending coordinates, that is, from the original image will be played in the picture to be deducted from the screen to display on the phone. The arrangement of this kind of resources program needs to write the algorithm to calculate the coordinates of the picture.
<ignore_js_op>
3. Animation editor handles animations
Game companies will have their own animation editor, the advantage of the animation editor is
1. Reduce the image size to save memory space
2. Shorten the art to coordinate time, because if there is no editor art is painful need a picture of a picture of the coordinates, all is physical activity.
3. Full data-driven animation, animation problem programs do not change code. The bugs are all fine art, hehe.
The animation editor is generated by coordinates that tell each point of the picture each dot of the animation to be stitched together each coordinate program needs to edit the generated coordinates to parse the resulting XML file from the animation editor and then draw the game animation. Auroragt Animation Editor is the author's most used animation editor It's very powerful to make any animation. I do not explain anything about the parsing and use of this editor for commercial use. If just want to study I put the editor of the post, we can study each other to discuss each other to learn from each other.
: <ignore_js_op>Auroragt.rar (1.51 MB, download count: 2046)
<ignore_js_op>
To everyone to see the resulting animation is very beautiful, it is not very to force it hehe.
<ignore_js_op>
<ignore_js_op>
I use the code to explain in detail the first and the second game animation code implementation method.
I wrote an animation class myself to handle the animation, I need to call the animation only needs the new animation object to pass in the animation required parameters by calling the Drawanimation method to play the animation by the frame. If it is purely learning, I think this class is enough to learn to use.
- Package Cn.m15.xys;
- Import Java.io.InputStream;
- Import Android.content.Context;
- Import Android.graphics.Bitmap;
- Import Android.graphics.BitmapFactory;
- Import Android.graphics.Canvas;
- Import Android.graphics.Paint;
- public class Animation {
- /** Last frame playback time **/
- Private long mlastplaytime = 0;
- /** play the ID of the current frame **/
- private int Mplayid = 0;
- /** Animated Frame Number **/
- private int mframecount = 0;
- /** for storing animated resource pictures **/
- Private bitmap[] Mframebitmap = null;
- /** whether the loop plays **/
- Private Boolean misloop = false;
- /** Play End **/
- Private Boolean misend = false;
- /** animation play Gap time **/
- private static final int anim_time = 100;
- /**
- * Constructor function
- * @param context
- * @param framebitmapid
- * @param isloop
- */
- Public Animation (context context, int [] Framebitmapid, Boolean isloop) {
- Mframecount = Framebitmapid.length;
- Mframebitmap = new Bitmap[mframecount];
- for (int i =0; i < Mframecount; i++) {
- Mframebitmap[i] = Readbitmap (Context,framebitmapid[i]);
- }
- Misloop = Isloop;
- }
- /**
- * Constructor function
- * @param context
- * @param framebitmap
- * @param isloop
- */
- Public Animation (context context, Bitmap [] Framebitmap, Boolean isloop) {
- Mframecount = Framebitmap.length;
- Mframebitmap = Framebitmap;
- Misloop = Isloop;
- }
- /**
- * Draw one of the frames in the animation
- * @param Canvas
- * @param paint
- * @param x
- * @param y
- * @param Frameid
- */
- public void Drawframe (canvas canvas, paint paint, int x, int y,int frameid) {
- Canvas.drawbitmap (Mframebitmap[frameid], x, y, paint);
- }
- /**
- * Draw Animations
- * @param Canvas
- * @param paint
- * @param x
- * @param y
- */
- public void drawanimation (canvas canvas, paint paint, int x, int y) {
- Resume playback If no playback is complete
- if (!misend) {
- Canvas.drawbitmap (Mframebitmap[mplayid], x, y, paint);
- Long time = System.currenttimemillis ();
- if (Time-mlastplaytime > Anim_time) {
- mplayid++;
- Mlastplaytime = time;
- if (Mplayid >= mframecount) {
- Logo animation play End
- Misend = true;
- if (Misloop) {
- Set Loop playback
- Misend = false;
- Mplayid = 0;
- }
- }
- }
- }
- }
- /**
- * Read Image Resources
- * @param context
- * @param resId
- * @return
- */
- Public Bitmap Readbitmap (context context, int resId) {
- Bitmapfactory.options opt = new bitmapfactory.options ();
- Opt.inpreferredconfig = Bitmap.Config.RGB_565;
- Opt.inpurgeable = true;
- Opt.ininputshareable = true;
- Get a picture of a resource
- InputStream is = Context.getresources (). Openrawresource (ResId);
- Return Bitmapfactory.decodestream (IS, null, opt);
- }
- }
Copy Code
Everybody look at my game demo use up and Down buttons to play up and down left to right character walking animation.
<ignore_js_op>
<ignore_js_op>
<ignore_js_op>
Finally because the code is more I do not post in the blog, the following gives the demo source of the Welcome to download reading each other to learn from each other, study
<ignore_js_op> Third-speaking frame animation. rar (426.78 KB, Downloads: 1354)
Ask.-Customized IT education platform, one-to-man service for cattle, questions and answers, development and programming social Headlines official website: www.wenaaa.com
QQ group 290551701 gathers a lot of Internet elite, technical director, architect, project Manager! Open source technology research, Welcome to the industry, Daniel and beginners are interested in engaging in IT industry personnel to enter!
Play and process of game frame animation for Android game development