-(void)moveCamera:(CGpoint)resultVector {
float centerX, centerY, centerZ;
float eyeX, eyeY, eyeZ;
[self.camera centerX:¢erX centerY=¢erY centerZ=¢erZ];
[self.camera eyeX:&eyeX eyeY:&eyeY eyeZ:&eyeZ];
float newX = (resultVector.x - actorOriginalPosition.x) + (actorOriginalPosition.x - screenSize.width/2);
float newY = (resultVector.y - actorOriginalPosition.y) + (actorOriginalPosition.y - screenSize.height/2);
[self.camera setCenterX:newX centerY=newY centerZ:-150.0f];
[self.camera setEyeX:newX eyeY=newY eyeZ:eyeZ];
}
这里resultVector是actor currentPosition
答案 0 :(得分:0)
:
CGPoint direction = [self getPoint:myBody->GetPosition()];
[self setPosition:direction];
- (CGPoint)getPoint:(b2Vec2)vec
{
CGSize screen = [[CCDirector sharedDirector] winSize];
float x = vec.x * PTM_RATIO;
float y = vec.y * PTM_RATIO;
x = MAX(x, screen.width/2);
y = MAX(y, screen.height/2);
float _x = area.width - (screen.width/2);
float _y = area.height - (screen.height/2);
x = MIN(x, _x);
y = MIN(y, _y);
CGPoint goodPoint = ccp(x,y);
CGPoint centerOfScreen = ccp(screen.width/2, screen.height/2);
CGPoint difference = ccpSub(centerOfScreen, goodPoint);
return difference;
}