人物绕着屏幕走
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 Camera mCamera;
private TiledTextureRegion mren;
@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
arg0)
throws Exception {
// TODO 自动生成的方法存根
BitmapTextureAtlas mTexture1 = new
BitmapTextureAtlas(getTextureManager(),
464,356,TextureOptions.BILINEAR_PREMULTIPLYALPHA);
mren=BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(
mTexture1, getAssets(), "ren.png", 0, 0,8,4);
mTexture1.load();
arg0.onCreateResourcesFinished();
}
@Override
public void onCreateScene(OnCreateSceneCallback
pOnCreateSceneCallback) throws Exception {
// TODO 自动生成的方法存根
Scene scene=new Scene();
final AnimatedSprite ab=new AnimatedSprite(20, 10, mren,
getVertexBufferObjectManager());
scene.attachChild(ab);
ab.registerEntityModifier(new SequenceEntityModifier(
new LoopEntityModifier(
new PathModifier(10,
new Path(5).to(ab.getX(), ab.getY()).to(ab.getX(),
CAMERA_HEIGHT-100).
to(MainActivity.CAMERA_WIDTH-100, CAMERA_HEIGHT-100).
to(CAMERA_WIDTH-100, 10).to(20, 10),new
IPathModifierListener() {
@Override
public void onPathWaypointStarted(PathModifier arg0, IEntity
arg1, int arg2) {
// TODO 自动生成的方法存根
switch(arg2){
case 0:ab.animate(new
long[]{90,90,90,90,90,90,90,90},0,7,true);break;
case 1:ab.animate(new
long[]{90,90,90,90,90,90,90,90},16,23,true);break;
case 2:ab.animate(new
long[]{90,90,90,90,90,90,90,90},24,31,true);break;
case 3:ab.animate(new
long[]{90,90,90,90,90,90,90,90},8,15,true);break;
}
}
@Override
public void onPathWaypointFinished(PathModifier arg0, IEntity
arg1, int arg2) {
// TODO 自动生成的方法存根
}
@Override
public void onPathStarted(PathModifier arg0, IEntity arg1)
{
// TODO 自动生成的方法存根
}
@Override
public void onPathFinished(PathModifier arg0, IEntity arg1)
{
// TODO 自动生成的方法存根
}
})
)));
pOnCreateSceneCallback.onCreateSceneFinished(scene);
}
@Override
public void onPopulateScene(Scene arg0,
OnPopulateSceneCallback arg1)
throws Exception {
// TODO 自动生成的方法存根
arg1.onPopulateSceneFinished();
}
}
主要还是IPathModifierListener这个类: 每完成两个点(Path中设置的点)的移动就回调IPathModifierListener监听中的onPathWaypointStarted方法。
onPathStarted:总路径的开始;onPathFinished:总路径的结束;onPathWaypointStarted:每一段的开始,int
arg2第几段;onPathWaypointFinished:每一段路径的结束。
private static final int CAMERA_WIDTH = 800;
private static final int CAMERA_HEIGHT = 480;
private Camera mCamera;
private TiledTextureRegion mren;
@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
arg0)
throws Exception {
// TODO 自动生成的方法存根
BitmapTextureAtlas mTexture1 = new
BitmapTextureAtlas(getTextureManager(),
464,356,TextureOptions.BILINEAR_PREMULTIPLYALPHA);
mren=BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(
mTexture1, getAssets(), "ren.png", 0, 0,8,4);
mTexture1.load();
arg0.onCreateResourcesFinished();
}
@Override
public void onCreateScene(OnCreateSceneCallback
pOnCreateSceneCallback) throws Exception {
// TODO 自动生成的方法存根
Scene scene=new Scene();
final AnimatedSprite ab=new AnimatedSprite(20, 10, mren,
getVertexBufferObjectManager());
scene.attachChild(ab);
ab.registerEntityModifier(new SequenceEntityModifier(
new LoopEntityModifier(
new PathModifier(10,
new Path(5).to(ab.getX(), ab.getY()).to(ab.getX(),
CAMERA_HEIGHT-100).
to(MainActivity.CAMERA_WIDTH-100, CAMERA_HEIGHT-100).
to(CAMERA_WIDTH-100, 10).to(20, 10),new
IPathModifierListener() {
@Override
public void onPathWaypointStarted(PathModifier arg0, IEntity
arg1, int arg2) {
// TODO 自动生成的方法存根
switch(arg2){
case 0:ab.animate(new
long[]{90,90,90,90,90,90,90,90},0,7,true);break;
case 1:ab.animate(new
long[]{90,90,90,90,90,90,90,90},16,23,true);break;
case 2:ab.animate(new
long[]{90,90,90,90,90,90,90,90},24,31,true);break;
case 3:ab.animate(new
long[]{90,90,90,90,90,90,90,90},8,15,true);break;
}
}
@Override
public void onPathWaypointFinished(PathModifier arg0, IEntity
arg1, int arg2) {
// TODO 自动生成的方法存根
}
@Override
public void onPathStarted(PathModifier arg0, IEntity arg1)
{
// TODO 自动生成的方法存根
}
@Override
public void onPathFinished(PathModifier arg0, IEntity arg1)
{
// TODO 自动生成的方法存根
}
})
)));
pOnCreateSceneCallback.onCreateSceneFinished(scene);
}
@Override
public void onPopulateScene(Scene arg0,
OnPopulateSceneCallback arg1)
throws Exception {
// TODO 自动生成的方法存根
arg1.onPopulateSceneFinished();
}
}
主要还是IPathModifierListener这个类: 每完成两个点(Path中设置的点)的移动就回调IPathModifierListener监听中的onPathWaypointStarted方法。
onPathStarted:总路径的开始;onPathFinished:总路径的结束;onPathWaypointStarted:每一段的开始,int
arg2第几段;onPathWaypointFinished:每一段路径的结束。
相关文章推荐
- 飞机
- 监听屏幕点击次数并显示
- andengine背景设置另一种方法
- 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 使用注解方式进行事务管理
- 夜间与日间模式的切换