CCSprite Direction Cococs2d 3.0

时间:2014-03-04 04:03:13

标签: cocos2d-iphone sprite

我如何直接拍摄精灵“墨水”?玩家Squiddy在屏幕上移动,我希望每次都能直接拍摄墨水。到目前为止,我的代码拍摄的是墨水,但它会将其拍摄到屏幕上的某个点

代码

CGPoint targetPosition = ccp(self.contentSize.width/2, self.contentSize.height/2 + self.contentSize.height);

ink = [CCSprite spriteWithImageNamed:@"MarioTube_Body_Rev.png"];
ink.position = Squiddy.position;
ink.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:ink.contentSize.width/2.0f andCenter:ink.anchorPointInPoints];
ink.physicsBody.collisionGroup = @"playerG roup";
ink.physicsBody.collisionType  = @"projectileCollision";
CCActionRotateBy *actionSpin = [CCActionRotateBy actionWithDuration:.5f angle:360];
[ink runAction:[CCActionRepeatForever actionWithAction:actionSpin]];
[_physicsWorld addChild:ink];

CCActionMoveTo *actionMove   = [CCActionMoveTo actionWithDuration:.75f position:targetPosition];
CCActionRemove *actionRemove = [CCActionRemove action];
[ink runAction:[CCActionSequence actionWithArray:@[actionMove,actionRemove]]];

1 个答案:

答案 0 :(得分:1)

正如我之前所说的那样,尝试对墨水施加一种力量或冲动。物理身体:

CGPoint force = ccpMult(ccp(0,90), 600); //x=0, y=90, force=600
[ink.physicsBody applyForce:force];

值为x = 0时,力会上升。只是玩价值观。 希望这有帮助