I have a bird class that is called inside MyScene (main game scene). This bird is a randomly moving NPC. It has an image for looking left & that image is flipped horizontally when it's flying right. It has no images for flying up or down. The bird class has a round & very small SKPhysicsBody in comparison to the entire body. This is because later on I want to use SKPhysicsJointPin to attach other small SKPhysicsBodies to it - they will be little worms. I made the bird SKPhysicsBody a rough size of the beak (kept it round) & placed it where the beak is drawn on the image. I did it like so:
minDiam = MIN(self.size.width, self.size.height);
minDiam = MAX(minDiam - 16, 4);
self.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:minDiam/3.0 center:CGPointMake(-9, -2)];
Inside my MyScene class, during gameplay, I'm trying to change the position of the physicsBody when the bird's left facing image is flipped to the right when it fly's to the right. And also to change it back to CGPointMake(-9, -2) when the bird is flying left again. It's very important that the coordinates of the physicsBody don't just change from CGPointMake(-9, -2) to let's say CGPointMake(9, 2), but actually move/shift with maybe something like [SKAction moveToX:9 duration:0.01]. I have a game development reason for this later on in the future. I am unable to do this. Please help.
EDIT: The bird class is called by a function/method like so inside MyScene:
-(void)addBirdy
{
_birdy = [Birdy node];
_birdy.position = CGPointMake(self.size.width/2, self.size.height/2);
[self addChild:_birdy];
}
EDIT 2: Here is the facing direction code:
if (_birdy.physicsBody.velocity.dx < fX)
{
BIRDYASFacingDirection facingDir = _birdy.facingDirection;
facingDir = BIRDYfacingRight;
_birdy.facingDirection = facingDir;
//PhysicsBody movement to the right.
self.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:/*HOW TO RETAIN ORIGINAL VALUE?*/ center:/*HOW TO MOVE TO CGPointMake(9, 2)*/];
}
else
{
BIRDYASFacingDirection facingDir = _birdy.facingDirection;
facingDir = BIRDYfacingLeft;
_birdy.facingDirection = facingDir;
//PhysicsBody movement back to the left.
self.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:/*HOW TO RETAIN ORIGINAL VALUE?*/ center:/*HOW TO MOVE TO CGPointMake(-9, -2)*/];
}