我正在制作一个" Match-3"使用"扑克牌打造游戏"捻。
背景信息,不相关 - >这场比赛是Scat(或31)游戏的一个转折点。目标是制作3张相同套装的牌,其中Ace值为11(因此31是最高分)。
我已经让游戏运行得很好,在卡片被移除并且新卡片落入到位后发生了连击和链条。
我的下一个目标是让玩家知道可能的"交换"从最后一次交换后的几秒钟,然后每隔2秒,直到交换完成。我决定制作卡片"摇晃"半秒钟,它看起来很棒。
我的问题是,一旦交换发生,并且删除/删除/替换动画开始,"未使用"交换中的卡片一直在摇晃,当大型组合发生时这一点特别明显,这一张小卡片每隔两秒就会持续摇晃!
我意识到有一千种方法可以解决这个问题,但我真的没有遇到过这么好的方法!以下是我的相关功能:
- (void)updateWithTimeSinceLastUpdate:(CFTimeInterval)timeSinceLast
{
self.lastSwapTimeInterval += timeSinceLast;
if (self.lastSwapTimeInterval > 2)
{
self.lastSwapTimeInterval = 0;
[self showPossibleSwap];
}
}
-(void)update:(NSTimeInterval)currentTime
{
CFTimeInterval timeSinceLast = currentTime - self.lastUpdateTimeInterval;
self.lastUpdateTimeInterval = currentTime;
if (timeSinceLast > 1)
{
timeSinceLast = 1.0 / 60.0;
self.lastUpdateTimeInterval = currentTime;
}
[self updateWithTimeSinceLastUpdate:timeSinceLast];
}
-(void)animatePossibleSwap:(BGSSwap *)swap
{
BGSCard *first = swap.cardA;
BGSCard *second = swap.cardB;
const NSTimeInterval timeDiff = 0.05;
SKAction *rot15r = [SKAction rotateByAngle:-[self degreesToRadian:15] duration:0.05];
SKAction *rot30 = [SKAction rotateByAngle:[self degreesToRadian:30] duration:0.1];
SKAction *rot30r = [SKAction rotateByAngle:-[self degreesToRadian:30] duration:0.1];
[first.sprite runAction:[SKAction sequence:@[rot15r,rot30,rot30r,rot30,rot15r]]];
[second.sprite runAction:[SKAction sequence:@[[SKAction waitForDuration:timeDiff],rot15r,rot30,rot30r,rot30,rot15r]]];
}
-(void)showPossibleSwap
{
BGSSwap *swap = [self.level.possibleSwaps anyObject];
[self animatePossibleSwap:swap];
NSLog(@"Show Possible Swap NOW: %f",_lastSwapTimeInterval);
}
- (void)updateWithTimeSinceLastUpdate:(CFTimeInterval)timeSinceLast
{
self.lastSwapTimeInterval += timeSinceLast;
if (self.lastSwapTimeInterval > 2)
{
self.lastSwapTimeInterval = 0;
[self showPossibleSwap];
}
}
-(void)update:(NSTimeInterval)currentTime
{
CFTimeInterval timeSinceLast = currentTime - self.lastUpdateTimeInterval;
self.lastUpdateTimeInterval = currentTime;
if (timeSinceLast > 1)
{
timeSinceLast = 1.0 / 60.0;
self.lastUpdateTimeInterval = currentTime;
}
[self updateWithTimeSinceLastUpdate:timeSinceLast];
}
-(void)animatePossibleSwap:(BGSSwap *)swap
{
BGSCard *first = swap.cardA;
BGSCard *second = swap.cardB;
const NSTimeInterval timeDiff = 0.05;
SKAction *rot15r = [SKAction rotateByAngle:-[self degreesToRadian:15] duration:0.05];
SKAction *rot30 = [SKAction rotateByAngle:[self degreesToRadian:30] duration:0.1];
SKAction *rot30r = [SKAction rotateByAngle:-[self degreesToRadian:30] duration:0.1];
[first.sprite runAction:[SKAction sequence:@[rot15r,rot30,rot30r,rot30,rot15r]]];
[second.sprite runAction:[SKAction sequence:@[[SKAction waitForDuration:timeDiff],rot15r,rot30,rot30r,rot30,rot15r]]];
}
-(void)showPossibleSwap
{
BGSSwap *swap = [self.level.possibleSwaps anyObject];
[self animatePossibleSwap:swap];
NSLog(@"Show Possible Swap NOW: %f",_lastSwapTimeInterval);
}
答案 0 :(得分:0)
在摇动SKActions上使用withKey :
为每个动画命名。然后,当您确定动画不再适用时,可以使用removeActionforKey:
。