I'm using SKSpriteKit to make a fishing game. I have a sprite node for a hook, and for some fish (I extended the SKSpriteNode class for this). Ideally, the behavior when a fish gets caught on a hook is that the fishes mouth will move to the tip of the hook (using an action to do this) :
CGPoint hp = CGPointMake(self.hook.frame.size.width/2, 0);
CGPoint hookPoint = [self.scene convertPoint:hp fromNode:self.hook];
SKAction *moveAction = [SKAction moveTo:hookPoint duration:.1];
and then the fish will rotate down a bit to simulate hanging on a hook ( another action : )
SKAction * flip = [SKAction rotateToAngle:M_PI_4 duration:.1 ];
I think run these as such :
[fish runAction:[SKAction sequence:@[moveAction, flip]]];
this works more or less ( working out kinks based on the fish's direction)
What I later want to do is create a joint between the fish and the hook so if I move the hook around and it's already caught a fish, the fish follows along.
I do this :
SKPhysicsJointFixed *joint =
[SKPhysicsJointFixed jointWithBodyA:self.hook.physicsBody
bodyB:fish.physicsBody
anchor:hookPoint];
SKAction *createJoint = [SKAction runBlock:^{
[self.physicsWorld addJoint:joint];}];
[self.scene runAction:createJoint];
If I run the code without the joint, the fish will stay on the hook and rotate. HOWEVER, once the joint is create and the action ran, the rotation action from above DOES NOT GET INVOKED (the movement to the hook does though).
I have not the slightest idea of why this happens. Anyone have any pointers?