我想知道如何在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