【发布时间】:2016-10-04 06:41:25
【问题描述】:
我想知道如何在 Swift 3 中使用 Selector,包括 func 所需的括号中的值。
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 中的任何帮助?
谢谢。 :)
【问题讨论】:
标签: ios swift xcode selector swift3