Guten Tag,Warum führt das Ausführen einer Action innerhalb von update() zum Absturz der Anwendung?
Das Szenario ist dies, habe ich 3 Sprites und ich möchte Aktionen, um sie auszuführen Sequenz, in der update(). Eine andere Sache, wenn das Sprite die Aktion noch ausführt, erhält es keine neue Aktion, aber wenn es getan wird, wird die Aktion eine neue Aktion erstellen und dann ausführen.
Ich verwendete .isDone() für die Überprüfung. Hier
ist der Pseudocode:
-Legend zur besseren Lesbarkeit: SampleSprite - unter der Annahme, dass dies das Array von Sprites. isStillOnAction - boolean, true Wenn die Aktion gerade ausgeführt wird, false wenn nicht. Zufallszahl von 2-5 - ist eine Zufallszahl von 2 bis 5.
for(int ctr = 0; ctr < 3; ctr++){
if(!SpriteSample[ctr].isStillOnAction) // not currently executing action, so we can now assign an action
{
SampleSprite[ctr].isStillOnAction = true; // the isStillOnAction boolean is changed to true
if(SampleSprite[ctr].facingDirection == 1)
{
SampleSprite[ctr].moveAction = cocos2d::MoveBy::create(RANDOM NUMBER FROM 2-5, cocos2d::Vec2(0, 100));
SampleSprite[ctr].stoppingAction = cocos2d::MoveBy::create(RANDOM NUMBER FROM 2-5, cocos2d::Vec2(10, 0));
}
else if(SampleSprite[ctr].facingDirection == 2)
{
SampleSprite[ctr].moveAction = cocos2d::MoveBy::create(RANDOM NUMBER FROM 2-5, cocos2d::Vec2(0, -100));
SampleSprite[ctr].stoppingAction = cocos2d::MoveBy::create(RANDOM NUMBER FROM 2-5, cocos2d::Vec2(10, 0));
}
else if(SampleSprite[ctr].facingDirection == 3)
{
SampleSprite[ctr].moveAction = cocos2d::MoveBy::create(RANDOM NUMBER FROM 2-5, cocos2d::Vec2(-100, 0));
SampleSprite[ctr].stoppingAction = cocos2d::MoveBy::create(RANDOM NUMBER FROM 2-5, cocos2d::Vec2(0,10));
}
else if(SampleSprite[ctr].facingDirection == 4)
{
SampleSprite[ctr].moveAction = cocos2d::MoveBy::create(RANDOM NUMBER FROM 2-5, cocos2d::Vec2(100, 0));
SampleSprite[ctr].stoppingAction = cocos2d::MoveBy::create(RANDOM NUMBER FROM 2-5, cocos2d::Vec2(0, 10));
}
SampleSprite[ctr].moveStopAction = cocos2d::Sequence::create(SampleSprite[ctr].moveAction, SampleSprite[ctr].stoppingAction, nullptr);
SampleSprite[ctr].characterSprite->runAction(SampleSprite[ctr].moveStopAction);
}
else // currently executing action
{
if(SampleSprite[ctr].moveStopAction->isDone()) // check if done executing action
{
SampleSprite[ctr].isStillOnAction = false;
}
}}
Ergebnis: Es wird mit der Action-Sequenz aber nach, dass es friert dann Abstürze .
Was ist das mögliche Problem, das ich übersehen habe?
Vielen Dank im Voraus
Danke, ich scheinen zu versuchen, es in die andere Richtung unter Verwendung von Sequenz zu beheben, wie eine andere Leere Funktion innerhalb der Sequenz nennen? – nightrobin
'Aktion :: setCallbackFunc'? @nightrobin – Zen