So I've been seeing this issue for a while now. When using a delta method to change the location of a CCSprite, the placement of texture of my sprite slightly moves into the direction where I'm headed, while the physicsbody stays the same. This is really noticeable, since I'm using CCActionFollow to center this sprite in the view at all times. The code is displayed below. Is this normal behaviour, or am I perhaps overlooking something really obvious? Thanks!

- (void) move:(CCTime)delta toPosition:(CGPoint)point
OverworldScene * parentScene = (OverworldScene *)self.parent.parent.parent; //Go over physics node
OverworldLayer * parentLayer = (OverworldLayer *)self.parent.parent; //Go over physics node

//meewind of tegenwind?
float angleWind = parentScene.compass.rotation;
float angleShip = self.rotation;
float difference;
float windFactor;

if (angleWind > angleShip)
{difference = angleWind - angleShip;}
else{difference = angleShip - angleWind;}

if (difference > 180)
{difference = 360 - difference;}

//Incorporate wind power...
if (difference > 90)
{   //Tegenwind
    windFactor = 1-((((90- (180 - difference))/90))*(parentLayer.windPower/12));
{   //Meewind
    windFactor = 1+((((90-difference)/90))*(parentLayer.windPower/12));

if (windFactor < 0.4){windFactor = 0.4;}

//point is the current position of the user's sprite
//a, b and c are the right triangle sides lengths formed by the caser sprite and the user's sprite positions
float a = ABS(self.position.y - point.y);
float b = ABS(self.position.x - point.x);
float c = sqrt(pow(a, 2) + pow(b, 2));

//angle of the hypotenuse
float beta_rad = asin(b/c);

//velocity in pixels per second (used to be 60)
c = 60 * self.velocityFactor * windFactor;    //Now accounts for windfactor!
parentScene.speedLabel.string = [NSString stringWithFormat:@"Speed %.1f knots", self.velocityFactor * (60*windFactor)/8];

//x-axis velocity component
float x = c * sin(beta_rad);
//y-axis velocity component
float y = c * cos(beta_rad);

//adjustments based on position of the this (chaser) sprite and the user's sprite, if chaser is on the right or below the user's sprite it is needed to reverse the velocity vector component x and y
if (self.position.x > point.x) x *= -1;
if (self.position.y > point.y) y *= -1;

//final velocity vector
CGPoint velocityVector = CGPointMake(x, y);
CGPoint newPosition = ccpAdd(self.position, ccpMult(velocityVector, delta));

//NSLog(@"Updating position: %@", NSStringFromCGPoint(newPosition));

//Only update in case new position is in bounds
if (newPosition.x < 0 || newPosition.x > parentLayer.contentSize.width)
    newPosition = CGPointMake(self.position.x, newPosition.y);

if (newPosition.y < 0 || newPosition.y > parentLayer.contentSize.height)
    newPosition = CGPointMake(newPosition.x, self.position.y);

self.position = newPosition;


So I figured that setting the location of a node without forces has this effect on the camera. Simply use forces or set the velocity of your node.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.