我想知道如何使用 SpriteKit 物理基于起点在锥形中发射射弹?目前我只使用以下循环(它不以初始滑动为中心):
float distance = DistanceBetweenTwoPoints(_startSwipe, _endSwipe);
float cballDx = (_endSwipe.x - _startSwipe.x) / distance;
float cballDy = (_endSwipe.y - _startSwipe.y) / distance;
for (int i = 0; i < playerShip.cannons; i++) {
SKSpriteNode *cannon = [SKSpriteNode spriteNodeWithImageNamed:@"cball"];
cannon.name = @"cball";
cannon.position = _touchedShip.position;
cannon.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:cannon.size.width * 0.5];
cannon.physicsBody.dynamic = YES;
cannon.physicsBody.allowsRotation = NO;
cannon.physicsBody.friction = 0.0;
cannon.physicsBody.linearDamping = 0.0;
cannon.physicsBody.categoryBitMask = cannonCategory;
cannon.physicsBody.velocity = CGVectorMake(cballDx * 150 + i * 5, cballDy * 150);
[self addChild:cannon];
}
任何帮助是极大的赞赏!