0
votes

I am trying to make a parent and child sprite node and add the texture/animation and xScale to the child and "physicsBody" to the parent (parent as a wrapper that holds only to the physics body?)

at the moment I've only got SKSpritenode *arrowParentNode; which gives me the following error:

"Attempted to add nil node to parent".

Bellow is the code. I don't know what goes in the parent if the texture and animation is on the child? I am not sure if I'm doing this right at all, could anyone please explain?

I did also try _arrowParentNode = [ self arrowChildNode ]; Which gave me the following error after re entering the scene:

Attempted to add a SKNode which already has a parent. 

It didn't also solve the problem I had initially which was similar to this link.

Thanks in advance.

SKSpritenode *arrowParentNode;
.
..
...

-(void) arrowParentNode {

   // _arrowParentNode = [ ? ] //  <-- what goes in here if the textures are in within the child? 
    _arrowParentNode.anchorPoint = CGPointMake(0.2, 0.75);
    _arrowParentNode.physicsBody=[SKPhysicsBody bodyWithRectangleOfSize:_brick.size];
    _arrowParentNode.physicsBody.dynamic =NO;
    _arrowParentNode.physicsBody.affectedByGravity=YES;
    _arrowParentNode.physicsBody.collisionBitMask = pengCategory;
    _arrowParentNode.physicsBody.contactTestBitMask = chickenCategory;
    [self addChild:_arrowParentNode];

}

- (SKSpriteNode *) arrowChildNode {
   SKSpritenode * arrowTexture = [[SKSpriteNode alloc] initWithImageNamed:ARROW_SPR_ARROW0001];

    SKAction *sharkOCAnimation = [SKAction animateWithTextures:ARROW_ANIM_BALL timePerFrame:0.02];

    SKAction *scaleBall = [SKAction scaleTo:-1 duration:0];

    [_arrowParentNode addChild:_arrowTexture];

    return _arrowTexture;
}
1

1 Answers

0
votes

You need to create a plain SKNode and assign it:

_arrowParentNode = [SKNode node];

Also change the variable declaration from SKSpriteNode to:

SKNode* _arrowParentNode;