Android游戏开发之游戏帧动画的播放与处理
| [日期:2011-08-12] |
来源:Linux社区
作者:雨松MOMO |
[字体:大 中 小]
|
- 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 {
-
-
- private long mLastPlayTime = 0;
-
- private int mPlayID = 0;
-
- private int mFrameCount = 0;
-
- private Bitmap[] mframeBitmap = null;
-
- private boolean mIsLoop = false;
-
- private boolean mIsend = false;
-
- private static final int ANIM_TIME = 100;
-
-
-
-
-
-
-
-
- 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;
- }
-
-
-
-
-
-
-
- public Animation(Context context, Bitmap [] frameBitmap, boolean isloop) {
- mFrameCount = frameBitmap.length;
- mframeBitmap = frameBitmap;
- mIsLoop = isloop;
- }
-
-
-
-
-
-
-
-
-
-
-
- public void DrawFrame(Canvas Canvas, Paint paint, int x, int y,int frameID) {
- Canvas.drawBitmap(mframeBitmap[frameID], x, y, paint);
- }
-
-
-
-
-
-
-
-
-
- public void DrawAnimation(Canvas Canvas, Paint paint, int x, int y) {
-
- if (!mIsend) {
- Canvas.drawBitmap(mframeBitmap[mPlayID], x, y, paint);
- long time = System.currentTimeMillis();
- if (time - mLastPlayTime > ANIM_TIME) {
- mPlayID++;
- mLastPlayTime = time;
- if (mPlayID >= mFrameCount) {
-
- mIsend = true;
- if (mIsLoop) {
-
- mIsend = false;
- mPlayID = 0;
- }
- }
- }
- }
- }
-
-
-
-
-
-
-
- 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;
-
- InputStream is = context.getResources().openRawResource(resId);
- return BitmapFactory.decodeStream(is, null, opt);
- }
- }

评论声明
- 尊重网上道德,遵守中华人民共和国的各项有关法律法规
- 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
- 本站管理人员有权保留或删除其管辖留言中的任意内容
- 本站有权在网站内转载或引用您的评论
- 参与本评论即表明您已经阅读并接受上述条款
|
|
第 3 楼 dun 发表于 2012/8/11 19:57:44我想知道 生成的sprite文件具体怎么在代码中使用的啊 第 2 楼 阿周 发表于 2011/11/1 11:44:57为什么 http://linux.linuxidc.com/上面的资料,我都下载不了啊! 第 1 楼 qinglfxy 发表于 2011/10/8 17:46:24非常感谢提供的资料。
|
|