1

I am trying to add SKEmitterNode to the ball SKSpriteNode as a child.But also at the same time, I am rotating my ball node. But the problem is, the rotation of the ball node causes the emitter node to rotate (as the emitter node is child to ball node). Is there anything I could do to not rotate the emitter node,but rotate the ball node?

I added the ball node as:

SKSpriteNode * ball = [SKSpriteNode spriteNodeWithImageNamed:imageName];
ball.name=name;
ball.size=size;
ball.anchorPoint=CGPointMake(0, 0);

[self addChild:ball];

and I added the emitter node as:

 SKEmitterNode *burstEmitter =
 [NSKeyedUnarchiver unarchiveObjectWithFile:_emitterNodePath];
 [ball addChild:burstEmitter];

and when ball hits the wall, I am rotating the ball:

-(void)didBeginContact:(SKPhysicsContact *)contact
{

  SKSpriteNode * firstNode = (SKSpriteNode*)contact.bodyA.node;
  SKSpriteNode *  secondNode = (SKSpriteNode *)contact.bodyB.node;
  if (firstNode.physicsBody .categoryBitMask == wallHitCategory ||  secondNode.physicsBody.categoryBitMask == wallHitCategory) {

        NSLog(@"first sound and then rotate ball");
        [self runAction:[SKAction playSoundFileNamed:@"basketBall bounce.WAV" waitForCompletion:NO]];
        secondNode.anchorPoint=CGPointMake(0.5, 0.5);
            [secondNode runAction:[SKAction rotateByAngle:degToRad(180.0f) duration:3.0]];

    }
}

Is it possible to rotate the parent node but not its child node?

Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
  • 1
    I don't know how helpful will it be but you could rotate the child node in opposite direction of the parent node then maybe it will be smooth enough that the eye won't see the changes, as for another approach maybe a pinJoint could help -Hope it's helpful – Coldsteel48 Dec 14 '15 at 14:49
  • Thanks for the tip, I will try it and get back to you. – Teja Nandamuri Dec 14 '15 at 14:50
  • 3
    Is there any reason you can't create an invisible node that the ball and emitter node would both be children of? The invisible node would then determine both their positions but the ball node would rotate independently of the emitter. – Sean G Dec 14 '15 at 16:23
  • 1
    nope, I didnt think that way. That should be a good hack to make it work. I will try that too!!! Thanks @SeanG – Teja Nandamuri Dec 14 '15 at 16:25
  • 1
    Both user3351949 and SeanG provide an excellent answer, and should make them answers as such to receive proper votes and credit. Basically how I would design this is, if only 1 child does not listen to the rotation of the parent, use user3351949's answer, if multiple children do not rotate, use SeanGs answer, but instead, make a parent node, 2 children nodes (one that rotate, and one that does not) and place all other nodes in their respective child node of the parent – Knight0fDragon Dec 14 '15 at 16:30
  • 1
    do you mean SeanG answer @Knight0fDragon? I didnt provide any answer ;) – Teja Nandamuri Dec 14 '15 at 16:32
  • 1
    yes, sorry LOL you are the poster – Knight0fDragon Dec 14 '15 at 16:33

2 Answers2

2

You could rotate the child node in opposite direction of the parent node then maybe it will be smooth enough that the eye won't see the changes, As for another approach maybe a pinJoint could help

Also a SeanG's Comment is pretty well! I would prefer this solution because it seems to be better cpu performance - wise!

Having an invisible node as a parent node for both the ball and the emitter node, then when you will rotate the ball emitter node wouldn't be affected by rotation.

  • Hope it's helpful
Coldsteel48
  • 3,482
  • 4
  • 26
  • 43
2

I'll post my comment as an answer since it sounds like there's no reason it wouldn't work.

I would personally create a main node that the emitter and sprite node would both be children of. If all you do is add child nodes the parent node will effectively be invisible. Then you can move the parent node around as a whole but the individual children can be rotated independently.

Sean G
  • 479
  • 4
  • 9