我正在做这个视频教程: http://www.spritebuilder.com/getting-started/
一切正常,但是我射击的鸟没有速度。他们只是跌倒了。
希望你们有一个解决方案!提前谢谢!
这是我的lauchBird函数:
-(void)launchBird:(id)sender
{
//calc rotation
float rotationRadians = CC_DEGREES_TO_RADIANS(_launcher.rotation);
//vector for rotation
CGPoint directionVector = ccp(sinf(rotationRadians), cosf(rotationRadians));
CGPoint ballOffset = ccpMult(directionVector, 50);
//ball (bird)
CCNode* ball = [CCBReader load:@"Bird"];
ball.position = ccpAdd(_launcher.position, ballOffset);
//add ball to physicsNode
[_physicsNode addChild:ball];
//make impulse and apply force
CGPoint force = ccpMult(directionVector, 50000);
[ball.physicsBody applyForce:force];
}
答案 0 :(得分:2)
正如Allen S所建议的那样,你需要在球上添加一个physicsBody。你可以通过
来做到这一点int padding = 5;
CGFloat radius = 0.5*(ball.contentSize.width - padding);
//create a physics body
CCPhysicsBody* body = [CCPhysicsBody bodyWithCircleOfRadius:radius andCenter:ball.anchorPointInPoints];
body.density = 1.0;
body.friction = 0.5f;
ball.physicsBody = body; //assign the created body to the node's physicsBody property.
使用physicsBody的属性(密度,摩擦力,质量,弹性......)来获得理想的效果。