我有一个有趣的形式崩溃。我设置SKAction
喜欢
-(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]];
}
但是当我不先运行这个动作SKScene
并转到其他SKScene
时,当我设置相同的动作时,我会崩溃
但是,如果我首先运行此操作SKScene
,接下来一切正常SKScene
。
SpriteKit
里面有问题SKTexture
吗?
像这样运行我的动作
-(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];
}
}
}