教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 建筑文档 >

Android手机游戏开发知识点总结(9)

来源:网络收集 时间:2026-04-01
导读: public class GameView extends View{ private AnimationDrawable frameAnimation = null; Context mContext = null; public GameView(Context context){ super(context); mContext = context; ImageView img = new

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字,全部文档内容请下载后查看。喜欢就下载吧 ……
Android手机游戏开发知识点总结(9).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/438798.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)