[XNa] Use xNa to draw an animation

Source: Internet
Author: User

As we all know, animation is actually not moving, but it is continuous, and people will feel coherent. It is difficult for people to distinguish between 24 images or more every second.

In the WP project, the refresh rate is limited to 30 frames, which is lower than that of the PC platform, but it is already very high on handheld devices. previously, we used GDI to draw images on WM. If there is no alpha channel, it would be fine. If there is an alpha channel, how can we use alphablend, the rate of 10 frames is a dream (this is not an exaggeration ). there is video card acceleration (with the boss backing up) behind xNa, which is naturally a lot faster. The xNa demo on the PC basically does not consume much CPU.

OK, let's get down to the truth. If you want to draw an animation, you have to prepare multiple images and then upload one picture.

If it's just painting, you can do things without having to go into the xNa. the game class is the core. It loads textures, materials, and so on in loadcontent (of course, unloadcontent unloads these files), and the rest only needs to care about update and draw.

Draw is a real-name painting, and update is used to update the state. Generally, in update, it calculates the time elapsed, the collision of an object, and the input detection.

 

OK. Look at my animation. It's very simple. Don't laugh at it :-)

 
List <texture2d> person; texture2ddrawtexture = NULL;

The list of a person is the texture of a string of actions, and drawtexture is the texture to be drawn.

Load the texture in loadcontent:

For (INT I = 0; I <4; I ++) person. Add (this. content. Load <texture2d> (I. tostring ()));

Then, in update, calculate the image to be painted:

 
Drawtexture = person [index/15% person. Count]; index ++;

Finally, draw it in draw:

 
Spritebatch. Begin (); spritebatch. Draw (drawtexture, new vector2 (0, 0), color. White); spritebatch. End ();

The entire process is very simple. If you have read my previous article, it would not be difficult to use xNa to make a 2D game. The rest is the idea and workload.

 

I am not an artist myself. I can find some pictures on the Internet and use them together :-)

This is:

 

 

Here isSource code:

Http://files.cnblogs.com/egmkang/Animation.zip

 

PS:

another problem was found. On the PC, the refreshing rate is set to 60 frames, which is much larger than the consumption of 75 frames (I see J through CPU share ), say something

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.