我正在用Sprite Kit構建一個實現A * Pathfinding的遊戲。我正在使用角色用來計算路徑的網格系統(塊),它的效果很好。我的問題是動畫。Sprite套件延遲runAction完成?
我正在使用一個NSMutableArray來保存步驟,並在每次移動完成(runAction完成)時移除一個步驟。它的作品,但動畫完成之間凍結一微秒和新的舉動使它看起來「波濤洶涌」,它不是一個平穩的舉動...
我試了很多東西,唯一的作品是將持續時間改爲大約1.5秒來移動32px(它將成爲一個sloooooooow遊戲;))。當我想要我需要的時間(0.7)時,問題就在那裏。
我真的希望有人能幫助我。
下面是一些代碼:
-(void)animateChar {
self.currentStepAction = nil;
if (self.pendingMove != nil) {
tileMap *moveTarget = pendingMove;
self.pendingMove = nil;
self.shortestPath = nil;
[self moveToward:moveTarget];
return;
}
if (self.shortestPath == nil) {
return;
}
// WE HAVE REACHED OUR BLOCK! CHECK IF ITS CLICKED OR STROLLING
if ([self.shortestPath count] == 0) {
self.shortestPath = nil;
self.moving = FALSE;
self.strolling = FALSE;
if (self.minionBlock) {
CGPoint diff = ccpSub(self.minionBlock.position, self.parentBlock.position);
if (abs(diff.x) > abs(diff.y)) {
if (diff.x > 0) { [self runAnimation:_faceRight speed:0.3]; } else { [self runAnimation:_faceLeft speed:0.3]; }
} else {
if (diff.y > 0) { [self runAnimation:_faceUp speed:0.3]; } else { [self runAnimation:_faceDown speed:0.3]; }
}
// SET TIMER FOR REMOVING THE BLOCK. EVERY 0.5 SECONDS IT REMOVES X ENDURANCE.
self.blockTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(pickBlock) userInfo:nil repeats:YES];
} else {
[self setMinionBusy:FALSE];
[self runAnimation:_waiting speed:0.3];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(selectRandBlockAndMove) userInfo:nil repeats:NO];
}
return;
}
ShortestPathStep *s = [self.shortestPath objectAtIndex:0];
// CHECK HOLE ON NEXT DOWN
tileMap *checkHole = [s.theBlock getNeighbor:1];
if ([checkHole isBlockType] == 2) { // THERE IS A HOLE, WE CANT REACH!
if ([_scene getRecentBlock] == self.minionBlock) { [_scene controlHud:1]; }
[self removeBlockBar];
[self.minionBlock setOccupied:FALSE];
self.minionBlock = nil;
self.currentStepAction = nil;
self.pendingMove = nil;
self.shortestPath = nil;
[self runAnimation:_waiting speed:0.3];
[self addBubble:1];
if (!self.stuck) {
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(selectRandBlockAndMove) userInfo:nil repeats:NO];
}
return;
}
CGPoint futurePosition = s.theBlock.position;
CGPoint currentPosition = self.parentBlock.position;
CGPoint diff = ccpSub(futurePosition, currentPosition);
if (abs(diff.x) > abs(diff.y)) {
if (diff.x > 0) { [self runAnimation:_faceRight speed:0.2]; } else { [self runAnimation:_faceLeft speed:0.2]; }
} else {
if (diff.y > 0) { [self runAnimation:_faceUp speed:0.2]; } else { [self runAnimation:_faceUp speed:0.2]; }
}
self.parentBlock = s.theBlock;
currentStepAction = [SKAction moveTo:s.theBlock.position duration:1.2];
[self runAction:currentStepAction completion:^{
[self animateChar];
}];
[self.shortestPath removeObjectAtIndex:0];
}
沒人能幫忙嗎? – 2014-10-10 06:40:51