可変速度で発射するガン(すなわち、リボルバー対機関銃)の作成に問題があります。今、私は弾丸の実際の発射のために、このコードを持っている:xcode 8 swift 3スローダウン機能の「発射」時間
class GameScene: SKScene, SKPhysicsContactDelegate {
func spawnBullets(_ location: CGPoint){
let Bullet = SKSpriteNode(imageNamed: "circle")
Bullet.zPosition = -1
Bullet.position = CGPoint(x: ship.position.x,y: ship.position.y)
Bullet.size = CGSize(width: 30, height: 30)
Bullet.physicsBody = SKPhysicsBody(circleOfRadius: 15)
Bullet.physicsBody?.categoryBitMask = PhysicsCategory.Bullet
Bullet.physicsBody?.collisionBitMask = 0
Bullet.name = "Bullet"
Bullet.physicsBody?.isDynamic = true
Bullet.physicsBody?.affectedByGravity = false
self.addChild(Bullet)
var dx = CGFloat(location.x - base2.position.x)
var dy = CGFloat(location.y - base2.position.y)
let magnitude = sqrt(dx * dx + dy * dy)
dx /= magnitude
dy /= magnitude
let vector = CGVector(dx: 30.0 * dx, dy: 30.0 * dy)
Bullet.physicsBody?.applyImpulse(vector)
をして、私は、後のセクションで
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in (touches){
let location = touch.location(in: self)
if ball3.frame.contains(location) && base2.frame.contains(location) == false{
spawnBullets(location)}
これを持っている私は、タイマー機能を使用してみました、まだそれだけに思えます物事を悪化させる。現在、弾丸は毎秒60(またはfpsと同じレートで)発射されています。助けてくれてありがとう!