我想知道如何在Swift 3中使用Selector
,包括func
要求的括號中的值。我可以在Swift中使用帶括號的選擇器嗎?
let fireRecogniser = UISwipeGestureRecognizer(target: self, action: Selector(("shootShot")))
^即識別器我有但該方法「shootShot」具有用於Element
的參數其是enum
,我有。
這裏是 'shootShot' 功能:
func shootShot(type: Element) {
let shot = SKSpriteNode(imageNamed: "\(type)Shot")
shot.texture?.filteringMode = SKTextureFilteringMode.nearest
shot.position = CGPoint(x: -self.frame.width/2 /*playerframe*/, y: -(self.frame.height/2) + grnd.frame.height)
shot.setScale(1)
shot.physicsBody = SKPhysicsBody(circleOfRadius: (shot.frame.height/2))
shot.physicsBody?.affectedByGravity = false
shot.physicsBody?.allowsRotation = true
shot.physicsBody?.isDynamic = true
shot.physicsBody?.restitution = 0
shot.physicsBody?.angularDamping = 0
shot.physicsBody?.linearDamping = 0
shot.physicsBody?.friction = 0
shot.physicsBody?.categoryBitMask = Contact.Shot.rawValue
shot.physicsBody?.contactTestBitMask = Contact.Enemy.rawValue
self.addChild(shot)
// THIS WILL DEPEND ON DIFFICULTY
let spin = SKAction.rotate(byAngle: 1, duration: 0.3)
shot.run(SKAction.repeatForever(spin))
let move = SKAction.moveTo(x: self.frame.width/2, duration: 3.0)
let remove = SKAction.removeFromParent()
shot.run(SKAction.sequence([move, remove]))
}
正如你所看到的,該方法具有Element
的功能需要。
有關如何將該參數包含在我的Selector
中的幫助? 謝謝。 :)
更新和固定:) – pedrouan