我不完全明白在精靈套件動畫的最佳選擇; 1)蘋果在「冒險」例如使用這種方法,他們在內存中的動畫如圖片存儲的NSArray:存儲在內存NSArray與圖片或SKAction
static NSArray *sSharedTouchAnimationFrames = nil;
- (NSArray *)touchAnimationFrames {
return sSharedTouchAnimationFrames;
}
- (void)runAnimation
{
if (self.isAnimated) {
[self resolveRequestedAnimation];
}
}
- (void)resolveRequestedAnimation
{
/* Determine the animation we want to play. */
NSString *animationKey = nil;
NSArray *animationFrames = nil;
VZAnimationState animationState = self.requestedAnimation;
switch (animationState) {
default:
case VZAnimationStateTouch:
animationKey = @"anim_touch";
animationFrames = [self touchAnimationFrames];
break;
case VZAnimationStateUntouch:
animationKey = @"anim_untouch";
animationFrames = [self untouchAnimationFrames];
break;
}
if (animationKey) {
[self fireAnimationForState:animationState usingTextures:animationFrames withKey:animationKey];
}
self.requestedAnimation = VZAnimationStateIdle;
}
- (void)fireAnimationForState:(VZAnimationState)animationState usingTextures:(NSArray *)frames withKey:(NSString *)key
{
SKAction *animAction = [self actionForKey:key];
if (animAction || [frames count] < 1) {
return; /* we already have a running animation or there aren't any frames to animate */
}
[self runAction:[SKAction sequence:@[
[SKAction animateWithTextures:frames timePerFrame:self.animationSpeed resize:YES restore:NO],
/* [SKAction runBlock:^{
[self animationHasCompleted:animationState];
}]*/]] withKey:key];
}
我很欣賞這種方法,但我無法理解。將SKAction存儲在內存中不是更好的選擇,並且總是像這樣使用動畫?
[self runAction:action];
沒有使總是新的SKAction;
[SKAction animateWithTextures:frames timePerFrame:self.animationSpeed resize:YES restore:NO]
蘋果關於SpriteKit的文檔是......缺乏禮貌。我發現很多情況下,我的代碼比這裏的例子顯着更短,更甜。我一般信賴雷。 http://www.raywenderlich.com/45152/sprite-kit-tutorial-animations-and-texture-atlases – meisenman
在ray的教程中還介紹了這種方法,當動畫圖像存儲在NSArray – user3780799
不妨測試它的性能和答案你自己的問題。社區肯定會受益。 – meisenman