我有一种有趣的崩溃形式。我设置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
的所有内容都可以。{/ p>
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];
}
}
}
答案 0 :(得分:0)
不是100%肯定你在说什么,但如果我读了你,你在第一个场景中设置一个SKAction属性jumpAction,并在另一个场景的touchesBegan:
方法(?)中引用该动作:
[ninja runAction:self.jumpAction];
如果您没有为第二个场景设置self.jumpAction
,那么您基本上是在说[ninja runAction:nil];
我个人认为将动作尽可能接近应该执行它的节点(在本例中为精灵)是个好主意。如果你为不同的节点重复使用很多动作,那么创建一个ActionFactory类可能是另一种方法......