问题描述
我创建使用AndEngine库动态壁纸的服务。在屏幕上出现的是,从左边飞多次到右鸟雪碧。我使用LoopEntityModifier和PathModifier的解决方案。鸟是codeD随机开始Y位置每次它从左边的屏幕上显示出来。
I created a live wallpaper service using AndEngine library. On screen there is a bird Sprite that flying repeatedly from the left to right. I'm using LoopEntityModifier and PathModifier for the solution. The bird is coded to start randomly on Y-position everytime it shows up from the left screen.
在code是这样的:
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坐标值。
The problem is the Path's Y-coordinates value cannot be changed anymore when the LoopEntityModifier & PathModifier has run. I want everytime the loop started, I can set the new Path's Y-coordinate value again.
推荐答案
我觉得你可以通过覆盖onModifierFinished()和创造与改变的路径中的新PathModifier解决这个问题。它看起来是这样的:
I think you can get around this problem by overriding onModifierFinished() and creating a new PathModifier with the changed path. It would look something like this:
public LoopEntityModifier createModifier(Path path) {
return new LoopEntityModifier(new PathModifier(path)) {
@Override
public void onModifierFinished(final IModifier<IEntity> pEntityModifier, final IEntity pEntity) {
birdSprite.registerEntityModifier(createModifier(path));
}
}
}
birdSprite.registerEntityModifier(createModifier());
此仅当onModifierFinished作品()称为在每个循环结束时
This only works if onModifierFinished() is called at the end of every loop.
这篇关于如何随机设定PathModifier的坐标LoopEntityModifier的开端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!