andengine背景设置另一种方法
2016-07-27 17:51
288 查看
public class MainActivity extends BaseGameActivity {
private static final int CAMERA_WIDTH = 800;
private static final int CAMERA_HEIGHT = 480;
private TextureRegion mb;
private Camera mCamera;
@Override
public EngineOptions onCreateEngineOptions() {
// TODO 自动生成的方法存根
mCamera = new Camera(0,0,CAMERA_WIDTH,CAMERA_HEIGHT);
EngineOptions mEngineOptions = new EngineOptions(true,
ScreenOrientation.LANDSCAPE_FIXED,
new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),
mCamera);
return mEngineOptions;
}
@Override
public void onCreateResources(OnCreateResourcesCallback
pOnCreateResourcesCallback)
throws Exception {
// TODO 自动生成的方法存根
BitmapTextureAtlas mauto = new
BitmapTextureAtlas(getTextureManager(),
1366,768,TextureOptions.BILINEAR_PREMULTIPLYALPHA);//1366、768为图片像素,不能错.
mb=BitmapTextureAtlasTextureRegionFactory.createFromAsset(
mauto, getApplicationContext(), "background.jpg", 0, 0);
mauto.load();
pOnCreateResourcesCallback.onCreateResourcesFinished();
}
@Override
public void onCreateScene(OnCreateSceneCallback
pOnCreateSceneCallback) throws Exception {
// TODO 自动生成的方法存根
Scene scene=new Scene();
AutoParallaxBackground bg=new AutoParallaxBackground(0, 0, 0,
5);//最后一个参数设置每秒钟背景变化速度。
bg.attachParallaxEntity(new
ParallaxEntity(0,
new Sprite(0, CAMERA_HEIGHT-mb.getHeight(), mb,
getVertexBufferObjectManager())));//第一个参数为移动速度,设为0就不移动了。
scene.setBackground(bg);
pOnCreateSceneCallback.onCreateSceneFinished(scene);
}
@Override
public void onPopulateScene(Scene pScene,
OnPopulateSceneCallback pOnPopulateSceneCallback)
throws Exception {
// TODO 自动生成的方法存根
pOnPopulateSceneCallback.onPopulateSceneFinished();
}
}
这种方法运用了AutoParallaxBackground方法,意思是背景移动,但如果把移动速度设为0,也可以达到目的。
private static final int CAMERA_WIDTH = 800;
private static final int CAMERA_HEIGHT = 480;
private TextureRegion mb;
private Camera mCamera;
@Override
public EngineOptions onCreateEngineOptions() {
// TODO 自动生成的方法存根
mCamera = new Camera(0,0,CAMERA_WIDTH,CAMERA_HEIGHT);
EngineOptions mEngineOptions = new EngineOptions(true,
ScreenOrientation.LANDSCAPE_FIXED,
new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),
mCamera);
return mEngineOptions;
}
@Override
public void onCreateResources(OnCreateResourcesCallback
pOnCreateResourcesCallback)
throws Exception {
// TODO 自动生成的方法存根
BitmapTextureAtlas mauto = new
BitmapTextureAtlas(getTextureManager(),
1366,768,TextureOptions.BILINEAR_PREMULTIPLYALPHA);//1366、768为图片像素,不能错.
mb=BitmapTextureAtlasTextureRegionFactory.createFromAsset(
mauto, getApplicationContext(), "background.jpg", 0, 0);
mauto.load();
pOnCreateResourcesCallback.onCreateResourcesFinished();
}
@Override
public void onCreateScene(OnCreateSceneCallback
pOnCreateSceneCallback) throws Exception {
// TODO 自动生成的方法存根
Scene scene=new Scene();
AutoParallaxBackground bg=new AutoParallaxBackground(0, 0, 0,
5);//最后一个参数设置每秒钟背景变化速度。
bg.attachParallaxEntity(new
ParallaxEntity(0,
new Sprite(0, CAMERA_HEIGHT-mb.getHeight(), mb,
getVertexBufferObjectManager())));//第一个参数为移动速度,设为0就不移动了。
scene.setBackground(bg);
pOnCreateSceneCallback.onCreateSceneFinished(scene);
}
@Override
public void onPopulateScene(Scene pScene,
OnPopulateSceneCallback pOnPopulateSceneCallback)
throws Exception {
// TODO 自动生成的方法存根
pOnPopulateSceneCallback.onPopulateSceneFinished();
}
}
这种方法运用了AutoParallaxBackground方法,意思是背景移动,但如果把移动速度设为0,也可以达到目的。
相关文章推荐
- Struts2学习(四)OGNL标签介绍
- andengine背景
- Java跳出循环-break和continue语句
- Xcode中Build Configuration配置使用
- 深入理解RxJava的Side Effect Methods
- C++中输出指定位数的小数
- 架构图
- ios数据存储——数据库:SQlite3以及第三方库FMDB
- SqlServer与MySql的一些常用用法的差别
- android 命令隐藏导航栏以及显示电量
- 如何在windows上清除putty的密钥缓存
- 前端代码规范
- TCP协议详解(含长连接短连接的详解)
- 在android AndroidManifest.xml文件中怎样设置访问网络的权限
- MRC和ARC时期的@property参数
- Spring 使用注解方式进行事务管理
- 夜间与日间模式的切换
- C++中引用(&)的用法和应用实例
- 关于JVM内存区域划分
- 对于Fragment的一些理解