ios - Store in memory NSArray with pictures or SKAction -
ios - Store in memory NSArray with pictures or SKAction -
i don't understand best selection in sprite kit animation; 1) apple in "adventure" illustration utilize methodology, store in memory animation pictures in nsarray :
static nsarray *ssharedtouchanimationframes = nil; - (nsarray *)touchanimationframes { homecoming ssharedtouchanimationframes; } - (void)runanimation { if (self.isanimated) { [self resolverequestedanimation]; } } - (void)resolverequestedanimation { /* determine animation want 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; /* have running animation or there aren't frames animate */ } [self runaction:[skaction sequence:@[ [skaction animatewithtextures:frames timeperframe:self.animationspeed resize:yes restore:no], /* [skaction runblock:^{ [self animationhascompleted:animationstate]; }]*/]] withkey:key]; } i appreciate methodology, can't understand. storing skaction in memory not improve selection , utilize animation ?
[self runaction:action]; without making new skaction;
[skaction animatewithtextures:frames timeperframe:self.animationspeed resize:yes restore:no]
storing sktextures in nsarray recommended methodology used animation. can't found spritekit's documentation lacking on subject either, skaction has method animatewithtextures.
you indeed have skaction has given animation defined given nsarray, , maybe store in nsmutabledictionary animation name key. methodology see above has animatetextures line of code 1 time in fireanimationstate method, , can pass parameters such animationstate , key.
i think need take more surface @ methodology determine why chose go route. can see animationstate beingness utilized upon completion of animation , triggered else.
[self runaction:action] indeed simple, it's easy see it's not in way managing animationstate or key, have assume decided game needed do.
also maintain in mind methodology has higher level in given player class it's calling flexible method enacting animation given game entity , doing other things besides changing animation. in high level coding might doing more :
[self runanimation:@"jump"];
or
[self jump];
and because have designed low level scheme manages animation states , adds keys given management design, don't ever have code long line pointing out except 1 time in method see above.
a few reasons have found useful store nsarray of frames , not storing wrapped in skaction because want manipulate start frame of animation or run animation @ different speed. may or may not have need manipulate aspects of animation.
ios objective-c animation sprite-kit
Comments
Post a Comment