I have a crash in interesting form. I setUp SKAction
like
-(id)initWithSize:(CGSize)size
{
if (self = [super initWithSize:size])
{
self.backgroundColor = [SKColor colorWithWhite:255 alpha:1];
[self createNinja];
[self setUpJump];
}
return self;
}
- (void)setUpJump
{
SKTextureAtlas *jumpAtlas = [SKTextureAtlas atlasNamed:@"Ninja_jump"];
SKTexture *jump1 = [jumpAtlas textureNamed:@"Ninja_jump_1"];
SKTexture *jump2 = [jumpAtlas textureNamed:@"Ninja_jump_2"];
SKTexture *jump3 = [jumpAtlas textureNamed:@"Ninja_jump_3"];
SKTexture *jump4 = [jumpAtlas textureNamed:@"Ninja_jump_4"];
SKAction *jumpUpAnimation = [SKAction animateWithTextures:@[jump1, jump2, jump3, jump4]
timePerFrame:0.07];
SKAction *jumpDownAnimation = [SKAction animateWithTextures:@[jump3, jump2, jump1, [SKTexture textureWithImageNamed:@"Ninja"]]
timePerFrame:0.07];
SKAction *wait = [SKAction waitForDuration:0.3];
self.jumpAction = [SKAction sequence:@[jumpUpAnimation, wait, jumpDownAnimation]];
}
But when I don't run this action on first SKScene
and go to other SKScene
, when I set up the same action, I have a crash
But if I run this action on first SKScene
, everything is OK on next SKScene
.
Is there problem in SpriteKit
in SKTexture
?
Run my action like that
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches)
{
CGPoint location = [touch locationInNode:self];
SKSpriteNode *ninja = (SKSpriteNode *)[self childNodeWithName:@"ninja"];
if (location.x > 230 &&
(location.x < 419 && location.y > 500))
{
[ninja runAction:self.jumpAction];
}
}
}