游戏融合SDK开发
基本使用
自定义一个Activity继承TSplashActivity
public class TestSplashActivity extends TSplashActivity { @Override public int getBackgroundColor() { //当闪屏PNG图片无法铺满部分机型的屏幕时,设置与闪屏颜色配合的背景色会给用户更好的体验 return Color.WHITE; } @Override public void onSplashStop() { //闪屏结束后,启动游戏的Activity Intent intent = new Intent(this, MainActivity.class); startActivity(intent); this.finish(); }
}
清单文件中设置闪屏Activity为启动Activity
<activity android:name=".TestSplashActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:screenOrientation="portrait" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
TSplashActivity 基本实现
private RelativeLayout layout; //Activity的布局 private ImageView imageView;//显示闪屏的图片控件 private TSplashSequence sequence = new TSplashSequence();//闪屏对象队列 //子类实现的设置背景颜色 public abstract int getBackgroundColor(); //子类实现的闪屏结束 public abstract void onSplashStop();
onCreate函数中将闪屏对象添加到队列中
while (true) { if (count < assetPaths.length) { //assets文件中取图片 this.sequence.addSplash(new TAssetSpash(this.layout, this.imageView, assetDir + "/" + assetPaths[count])); } else { //res/drawable文件中取图片 int id = getResources().getIdentifier(resourcePrefix + count, "drawable", getPackageName()); if (id == 0) { break; } this.sequence.addSplash(new TResSplash(this.layout, this.imageView, id)); } count++; }
onResume函数中执行sequence.play方法
this.sequence.play(this, new TSplashListener() { public void onFinish() { TSplashActivity.this.onSplashStop(); } });
TSplashListener 监听闪屏结束
public abstract interface TSplashListener { public abstract void onFinish(); }
TSplash 闪屏对象接口
public abstract interface TSplash { public abstract void play(Activity paramActivity, TSplashListener paramTSplashListener); }
TBaseImageSplash 闪屏对象的基本实现
public abstract class TBaseImageSplash implements TSplash { //子类实现的加载图片方法 abstract void loadImage(Activity paramActivity, ImageView paramImageView, LoadSplashCallback paramLoadSplashCallback); @Override public void play(final Activity context, final TSplashListener listener) { loadImage(context, this.imageView, new LoadSplashCallback() { @Override public void onLoadSuccess() { //执行动画 TBaseImageSplash.this.playSplash(context, listener); } @Override public void onLoadFailed() { listener.onFinish(); } }); } //内部类监听加载是否成功 public static abstract interface LoadSplashCallback { public abstract void onLoadSuccess(); public abstract void onLoadFailed(); } }
TAssetSpash 加载assets文件夹下面的图片
public class TAssetSpash extends TBaseImageSplash { @Override void loadImage(final Activity context, final ImageView imageView, final TBaseImageSplash.LoadSplashCallback callback) { Bitmap bitmap = null; try { InputStream stream = context.getAssets().open( TAssetSpash.this.assetPath); bitmap = BitmapFactory.decodeStream(stream); } catch (IOException e) { Log.e("T", "load asset splash failed : " + TAssetSpash.this.assetPath, e); } if (bitmap == null) { callback.onLoadFailed(); } else { imageView.setImageBitmap(bitmap); callback.onLoadSuccess(); } } }
TResSplash 加载drawable 下的图片
public class TResSplash extends TBaseImageSplash { @Override void loadImage(Activity context, ImageView imageView, TBaseImageSplash.LoadSplashCallback callback) { imageView.setImageResource(this.resourceId); callback.onLoadSuccess(); } }
TSplashSequence 闪屏序列执行播放
public class TSplashSequence { private List<TSplash> list = new ArrayList<TSplash>(); public void addSplash(TSplash splash) { this.list.add(splash); } public void play(Activity context, TSplashListener listener) { play(context, listener, 0); } private void play(final Activity context, final TSplashListener listener, final int index) { if (index >= this.list.size()) { listener.onFinish(); } else { ((TSplash) this.list.get(index)).play(context, new TSplashListener() { public void onFinish() { TSplashSequence.this.play(context, listener, index + 1); } }); } } }
源码
https://github.com/huben/Splash
相关知识
游戏sdk开发
Android兼H5游戏SDK开发详解(原创)
android 游戏 sdk开发教程 安卓游戏sdk
游戏盾 隧道加密 sdk
游戏sdk工程师和java开发工程师有什么区别
游戏SDK架构介绍
游戏SDK到底是什么?
游戏融合SDK开发
SDK 和工具要求
从零学习SDK(1)什么是SDK,为什么要使用它
推荐资讯
- 1老六爱找茬美女的烦恼怎么过- 4999
- 2博德之门3黄金雏龙法杖怎么得 4867
- 3《大侠立志传》剿灭摸金门任务 4312
- 4代号破晓官方正版角色介绍 4023
- 5赛马娘锻炼到底的伙伴支援卡事 3802
- 6闪烁之光11月兑换码大全20 3774
- 7原神原海异种刷怪路线-原神原 3547
- 8爆梗找茬王厕所特工怎么通关- 3542
- 9《我的世界》领地删除指令是什 3440
- 10原神开局星落湖怎么出去 原神 3426