Ich habe eine Klasse, die Animation implementiert. Ich registriere diese Klasse als animiert bei meinem Formular. Es funktioniert, aber 1 von 20 (oder in der Nähe) ist es nicht registriert werden: animate()
wird überhaupt nicht aufgerufen.Codename One - Form.registerAnimated() manchmal nicht registrieren Animation
Am Beispiel unten sehen wir, dass RollAnim2.start()
aufgerufen wird, aber RollAnim2.animate()
ist nicht.
public class RollAnimation implements Animation {
public void start() {
myForm.registerAnimated(this);
Log.p("RollAnim "+this.id+" : starting!\ntargets: "+
+ targetFrames.toString() +"\ncurrent: " +
+ sTempFrames());
}
public void stop() {
myForm.deregisterAnimated(this);
Log.p("RollAnim "+this.id+" : stopped!\ntargets: "+
+targetFrames.toString() +
+"\ncurrent: " + sTempFrames());
}
@Override
public boolean animate() {
Log.p("RollAnim "+this.id+" : Animate()");
//Some mechanics here
if (blablabla) {
this.stop();
return false;
} else
return true;
}
Und log:
[Timer-20] 0:1:14,119 - RollAnim 2 : starting!
targets: [30, 60, 90, 50, 30, 40]
current: [90, 80, 70, 30, 80, 20]
[Timer-16] 0:1:14,119 - RollAnim 0 : starting!
targets: [0, 60, 70, 30, 50, 40]
current: [60, 0, 60, 80, 20, 80]
[Timer-19] 0:1:14,119 - RollAnim 4 : starting!
targets: [60, 60, 30, 50, 50, 0]
current: [80, 30, 0, 10, 20, 50]
[Timer-18] 0:1:14,119 - RollAnim 3 : starting!
targets: [70, 50, 70, 0, 70, 40]
current: [80, 20, 80, 10, 40, 0]
[Timer-17] 0:1:14,120 - RollAnim 1 : starting!
targets: [10, 20, 30, 10, 60, 10]
current: [50, 10, 40, 70, 90, 60]
[EDT] 0:1:14,120 - RollAnim 0 : Animate()
[EDT] 0:1:14,121 - RollAnim 4 : Animate()
[EDT] 0:1:14,121 - RollAnim 3 : Animate()
[EDT] 0:1:14,121 - RollAnim 1 : Animate()
[EDT] 0:1:14,139 - RollAnim 0 : Animate()
[EDT] 0:1:14,139 - RollAnim 4 : Animate()
[EDT] 0:1:14,139 - RollAnim 3 : Animate()
[EDT] 0:1:14,139 - RollAnim 1 : Animate()
[EDT] 0:1:14,154 - RollAnim 0 : Animate()
[EDT] 0:1:14,154 - RollAnim 4 : Animate()
***
[EDT] 0:1:14,725 - RollAnim 3 : stopped!
targets: [70, 50, 70, 0, 70, 40]
current: [70, 50, 70, 0, 70, 40]
[EDT] 0:1:14,878 - RollAnim 4 : stopped!
targets: [60, 60, 30, 50, 50, 0]
current: [60, 60, 30, 50, 50, 0]
[EDT] 0:1:15,28 - RollAnim 0 : stopped!
targets: [0, 60, 70, 30, 50, 40]
current: [0, 60, 70, 30, 50, 40]
[EDT] 0:1:15,58 - RollAnim 1 : stopped!
targets: [10, 20, 30, 10, 60, 10]
current: [10, 20, 30, 10, 60, 10]
Was soll ich tun, um dieses Problem zu lösen?
aktualisieren
Es ist nicht Timer & EDT Interaktion Problem. Geprüft von dieser Klasse als Vermittler:
public class AnimationCrutch implements Animation {
protected ArrayList<Animation> toRegister = new ArrayList<Animation>();
protected Form master;
public void registerAnimated (Animation animation) {
toRegister.add(animation);
}
public AnimationCrutch (Form master) {
this.master = master;
this.master.registerAnimated(this);
}
@Override
public boolean animate() {
if (toRegister.size() == 0) return false;
for (Animation anim : toRegister) {
this.master.registerAnimated(anim);
}
toRegister.clear();
return false;
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
}
}
Es fühlt sich an, als ob das Problem durch Timer -> EDT-Interaktion verursacht wird. –