Android手机游戏开发知识点总结(9)
public class GameView extends View{
private AnimationDrawable frameAnimation = null; Context mContext = null;
public GameView(Context context){ super(context); mContext = context;
ImageView img = new ImageView(mContext);//定义一个ImageView用来显示动画
img.setBackgroundResource(R.anim.frameanimation);//装载动画布局文件
frameAnimation = (AnimationDrawable) img.getBackground();//构建动画
frameAnimation.setOneShot( false ); //设置是否循环
this.setBackgroundDrawable(frameAnimation);//设置该类显示的动画 }
public void onDraw(Canvas canvas){ super.onDraw(canvas); }
public boolean onKeyUp(int keyCode, KeyEvent event){ switch ( keyCode ){
case KeyEvent.KEYCODE_DPAD_UP:
frameAnimation.start();//开始播放动画 break; }
return true; }
} 还许要在Acitivity类中实例化GameView对象才能显示。
=================================================================================================================================================== GIF动画播放
其原理:首先需要对GIF动画图像进行解码,然后将GIF中的每一帧分别提取出来保存到一个容器中,然后根据需要绘制每一帧,这样就可以轻松地实现GIF动画的播放了。
下面有个例子,可以在工作中直接使用。
public class GifDecoder{ private int E0; private int E1[]; private int E2; private int E6; private boolean E7; private int E8[]; private int width; private int height; private int ED; private boolean EE; private boolean EF; private int F0[]; private int F1; private boolean F2; private int F3; private long F4; private int F5;
private static final int F6[] = { 8, 8, 4, 2 };
private static final int F8[] = { 0, 4, 2, 1 }; int curFrame; int poolsize; int FA; byte C2[]; int FB; int FC; int FD;
public GifDecoder(byte abyte0[]){ E0 = -1;
E1 = new int[280]; E2 = -1; E6 = 0; E7 = false; E8 = null; width = 0; height = 0; ED = 0; EE = false; EF = false; F0 = null; F1 = 0; F5 = 0; curFrame = 0; C2 = abyte0; poolsize = C2.length; FA = 0; }
public boolean moreFrames(){ return poolsize - FA >= 16; }
public void nextFrame(){ curFrame++; }
public Bitmap decodeImage(){
return decodeImage(curFrame); }
public Bitmap decodeImage(int i){ if (i <= E0){ return null; }
if (E0 < 0){ if (!E3()){ return null; } if (!E4()){ return null; } } do{ if (!E9(1)){ return null; }
int j = E1[0]; if (j == 59){ return null; }
if (j == 33){ if (!E7()){ return null; } }
else if (j == 44){ if (!E5()){ return null; }
Bitmap image = createImage(); E0++; if (E0 < i){ image = null;
}else{ return image; } } }
while (true); }
public void clear(){ C2 = null; E1 = null; E8 = null; F0 = null; }
private Bitmap createImage(){ int i = width; int j = height; int j1 = 0; int k1 = 0;
int ai[] = new int[4096]; int ai1[] = new int[4096]; int ai2[] = new int[8192]; if (!E9(1)){ return null; }
int k = E1[0];
int[] image = new int[width * height]; int ai3[] = E8; if (EE){ ai3 = F0; }
if (E2 >= 0){ ai3[E2] = 0xffffff; }
int l2 = 1 << k; int j3 = l2 + 1;
…… 此处隐藏:560字,全部文档内容请下载后查看。喜欢就下载吧 ……相关推荐:
- [建筑文档]2018年公需课:专业技术人员创新能力与
- [建筑文档]2013年福建教师招考小学数学历年真题
- [建筑文档]高中信息技术课flash知识点总结 - 图文
- [建筑文档]电工实训 - 图文
- [建筑文档]最高院公告案例分析100篇(民商篇)
- [建筑文档]南开中学高2017级14-15学年(上)期末
- [建筑文档]五粮液集团战略分析
- [建筑文档]鲁教版(2012秋季版)九年级化学 酸碱
- [建筑文档]超星尔雅2017中国哲学概论自整理题库答
- [建筑文档]关于成为海口金盘饮料公司材料独家供货
- [建筑文档]LNG学习资料第一册 基础知识 - 图文
- [建筑文档]四年级品社下册《好大一个家》复习资料
- [建筑文档]现阶段领导权力腐败的特点及发展趋势
- [建筑文档]魏晋南北朝诗歌鉴赏—嵇康
- [建筑文档]坚持追求真爱是理智的行为 正方一辩稿
- [建筑文档]湘西州刑释解教人员帮教安置工作存在的
- [建筑文档]园林工程试题库及答案
- [建筑文档]计算机长期没有向WSUS报告状态
- [建筑文档]日语最新流行语
- [建筑文档]B62-016 景观进场交底专题会议
- 2018年中考语文课内外古诗词鉴赏专题复
- 高考试题研究心得体会
- C语言基础题及答案
- 电气控制及PLC习题及答案
- 都昌小学家长学校汇报材料
- GMAT作文模板正确使用方法
- 俄军办坦克大赛:中国99式有望与豹2A6
- 成本会计练习题
- 酒店餐饮业最流行的5S管理方法
- 2014-2015学年山东省菏泽市高二(下)
- 《黄鹤楼送孟浩然之广陵》教案、说课、
- 2013年结构化学自测题 有答案版
- 2011西安世界园艺博览会游览解说词(附
- 窗口文明单位示范单位创建活动总结
- 2018满分超星尔雅就业课后练习期末答案
- 韶山市城市总体规划-基础资料
- 苏教版第三单元知识点归纳
- 第4章 曲轴模态分析
- 加大查办案件力度的思考
- 武汉CPC导轨介绍




