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)));
...
}
}
問題がLoopEntityModifier & PathModifierが実行されたときのパスのY座標値はもう変更できませんです。ループが始まるたびに新しいパスのY座標値を設定することができます。
ありがとうございました。しかし、私はonModifierFinishedをオーバーライドするために匿名の内部クラスを作成するのではなく、現在のクラスを設定してリスナーを実装します:registerEntityModifier(new LoopEntityModifier(new PathModifier(10、path)、1、this)); loopCountパラメータを1に設定する必要があります。-1に設定した場合、必要に応じて機能しません。最後に、onModifierFinishedでclearEntityModifiers()を呼び出す必要はありません。それ以外の場合は動作しません。 – null