Android game development Research frame animation implementation

Source: Internet
Author: User



1. The principle frame of animation

The animation frame of the frame is animated by its name, and the picture is the frame animation. Frame animation and our childhood to see the principle of the cartoon is the same, in the same area high-speed switch pictures to show people a visual illusion feel like playing the animation, in fact, is only n pictures in a frame of the switch. If you don't know the camera, look.

p=992 "rel=" bookmark ">android Research game Development Camera update

What you see: the implementation of the character walk 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 up. Very easy bar, the other three direction to play the animation method similar to I am no longer one by one example.

\

"Class=" Size-full wp-image-1001 aligncenter "alt=" Android research game development Frame animation Implementation (iii)-1th | Successful Smart network-focus on game programming development!

"Src=" http://www.cgzhw.com/wp-content/uploads/2014/07/121.jpg "style=" ">2. Raw File Animation resource original file png Generally there are three forms of presentation please listen to me carefully. 1. Each frame is seen in a PNG picture each frame in each set of animations is a PNG image, and the animation needs to toggle the entire picture to achieve the animation effect. The code just needs to complete the next frame picture to cover the previous frame of the picture is OK. The arrangement of such resources is the simplest in the program algorithm.

"Src=" http://www.cgzhw.com/wp-content/uploads/2014/07/216.jpg "style=" ">2. All animation frames exist in a PNG image You can see a PNG that holds all of the characters ' frame animations, and when the animation is played, the program needs to calculate the starting and ending coordinates of the picture that will be played in the original image, that is, the image to be played out from the original image. So that it appears on the phone screen.

The arrangement of such resources requires the programming of the algorithm to calculate the coordinates of the picture. 3. Animation editor Processing animation 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, due to the assumption that there is no editor art very painful need a picture of a picture of the coordinates. It's all about physical activity.


3. Completely data-driven animation, animation problem programs do not change code.

The bugs are all fine art. Oh.

The animation editor generates the fact that the coordinates tell each point of the picture the dots of each animation are stitched together by each coordinate program that needs to be edited by the animation editor generated by the generated coordinates to parse the XML file and then draw out the game animation. Auroragt Animation Editor is the author of the most used animation editor it has a powerful ability to create random animation.

Because of the commercial use of the editor for the analysis and use I do not do whatever explanation.

If I just want to learn how to post the editor, we can study each other and discuss with each other.

Source code Download: AURORAGT

"Class=" Alignnone size-full wp-image-1004 "alt=" Android research game development Frame animation Implementation (iii)-4th | Successful Smart network-focus on game programming development! "Src=" http://www.cgzhw.com/wp-content/uploads/2014/07/414.jpg "style=" ">

to everyone to see the resulting animation is very beautiful, it is not very much to the force of hehe. I use the code to explain the first and another game animation code implementation method.

I wrote an animation class myself to handle the playback animation. The need to invoke an animation requires only the required number of new animation objects to pass in the animation by calling the Drawanimation method to play the animation on the frame. I think this class is enough to learn to use if it's purely learning.

<strong>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 {/** Previous frame playback time **/private long mlastplaytime = 0;    /** plays 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 ends **/private Boolean misend = false;    /** animation play Gap time **/private static final int anim_time = 100; /** * Constructor * @param context * @param framebitmapid * @param isloop */Public Animation (Context cont ext, 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 * @param context * @param framebitmap * @param isloop */public Animation (context con Text, 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 */Publ IC void Drawframe (canvas canvas, paint paint, int x, int y,int frameid) {canvas.drawbitmap (Mframebitmap[frameid], X, Y, PA    int); /** * Animate * @param Canvas * @param paint * @param x * @param y */public void Drawanimati  On (canvas canvas, paint paint, int x, int y) {//assuming that no playback is complete, continue playing if (!misend) {Canvas.drawbitmap (Mframebitmap[mplayid], X,    Y, paint);    Long time = System.currenttimemillis ();    if (Time-mlastplaytime > Anim_time) {mplayid++;mlastplaytime = time;if (Mplayid >= mframecount) {//Flag animation play End    Misend = true;    if (misloop) {//set loop playback misend = False;mplayid = 0; }}    }}}/** * Read Picture resource * @param context * @param resId * @return */public Bitmap Readbitmap (C Ontext context, int resId) {bitmapfactory.options opt = new bitmapfactory.options (); opt.inpreferredconfig = bitmap.config.rgb_565;opt.inpurgeable = True;opt.ininputshareable = true;//Get the resource picture inputstream is =    Context.getresources (). Openrawresource (resId); return Bitmapfactory.decodestream (IS, null, opt); }}</strong>
Everybody look at my game demo use up and Down buttons to play up and down left to right character walking animation.

"Class=" Size-full wp-image-1009 aligncenter "alt=" Android research game development Frame animation Implementation (iii)-8th | Successful Smart network-focus on game programming development. "Src=" http://www.cgzhw.com/wp-content/uploads/2014/07/82.jpg "style=" ">

Finally because the code is more I do not post in the blog, the following gives the demo source code download welcome everyone to download reading to learn from each other. Study each other. Discuss with each other and hope that we can make progress together.

source code Download: Animation

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Android game development Research frame animation implementation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.