您的位置:首页 > 其它

人物绕着屏幕走

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:每一段路径的结束。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: