1
我有一個類CharacterCreator這使得玩家和裏面我有這些功能,使玩家拍攝:Swift:如何讓玩家武器生成子彈?
func shoot(scene: SKScene) {
if (playerArmed) {
let bullet = self.createBullet()
scene.addChild(bullet)
bullet.position = playerWeaponBarrel.position
bullet.physicsBody?.velocity = CGVectorMake(200, 0)
}
}
func createBullet() -> SKShapeNode {
let bullet = SKShapeNode(circleOfRadius: 2)
bullet.fillColor = SKColor.blueColor()
bullet.physicsBody = SKPhysicsBody(circleOfRadius: bullet.frame.height/2)
bullet.physicsBody?.affectedByGravity = false
bullet.physicsBody?.dynamic = true
bullet.physicsBody?.categoryBitMask = PhysicsCategory.Bullet
bullet.physicsBody?.contactTestBitMask = PhysicsCategory.Ground
bullet.physicsBody?.collisionBitMask = PhysicsCategory.Ground
return bullet
}
的playerWeaponBarrel
子節點就是子彈應產卵。會發生什麼事是,當我叫拍在GameScene()函數:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
let touchedNode = self.nodeAtPoint(location)
if (touchedNode == fireButton) {
Player.shoot(self.scene!)
}
它只是不會創建在playerWeaponBarrel子彈。我如何做到這一點?
是啊,我只是現在這樣做!謝謝您的回答 :) –