1
我使用AndEngine库创建了一个动态壁纸服务。在屏幕上,有一只鸟从左到右反复飞行。我正在使用LoopEntityModifier和PathModifier作为解决方案。每次从左侧屏幕显示时,该鸟被编码在Y位置随机开始。如何在LoopEntityModifier的开始处随机设置PathModifier的坐标?
的代码是这样的:
public class MyLiveWallpaperService extends BaseLiveWallpaperService {
private AnimatedSprite birdSprite;
...
public Scene onLoadScene() {
...
float[] coordY = generateRandomCoordY(); // my custom function to generate random array of Y-coordinates
Path path = new Path(coordX, coordY); // set the coordinate to Path object
// register the modifiers (for the one who is curious, 1st argument of PathModifier is the duration,
// but it has nothing to do with the question)
birdSprite.registerEntityModifier(new LoopEntityModifier(new PathModifier(10, path)));
...
}
}
的问题是路径的Y坐标值不能再改变LoopEntityModifier & PathModifier已经用完时。我希望每次循环开始时,我都可以再次设置新路径的Y坐标值。
谢谢,你的想法很有效。但我不创建匿名内部类来覆盖onModifierFinished,而是设置当前类来实现监听器:registerEntityModifier(new LoopEntityModifier(new PathModifier(10,path),1,this));. loopCount参数必须设置为1,如果设置为-1,它不会按需要工作。最后,不需要在onModifierFinished中调用clearEntityModifiers(),否则它不会工作。 – null 2012-04-23 03:50:30