を使用して静止背景の上に移動背景を作成しようとしていますがNSTimer
、コマンドを呼び出して別の子を追加するまでは正常に機能します。これが私が得ているエラーです。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attemped to add a SKNode which already has a parent: <SKSpriteNode> name:'(null)' texture:[<SKTexture> 'groundGrass.png' (53 x 71)] position:{159, 35} size:{808, 71}
地面を移動するコードは次のとおりです。
-(void)moveGroundGrass{
groundGrass.position = CGPointMake(groundGrass.position.x -1, groundGrass.position.y);
if (groundGrass.position.x < 160){
[self addChild:groundGrass];
}
残りは次のとおりです。
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
/* Setup your scene here */
SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"background"];
background.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
background.xScale = 0.9;
background.yScale = 1.1837f;
[self addChild:background];
groundGrass = [SKSpriteNode spriteNodeWithImageNamed:@"groundGrass"];
groundGrass.position = CGPointMake (404, 35);
[self addChild:groundGrass];
moveGround = [NSTimer scheduledTimerWithTimeInterval:0.01f target:self selector:@selector(moveGroundGrass) userInfo:nil repeats:YES];
}
return self;
}
GroundGrass.png が別の子ノードを追加する画面上のポイントを通過すると、クラッシュします...