我在Laser.swift中有一个shootLaser函数,它是GameScene
的单独文件。我正在尝试使用轻敲手势识别器来激发激光,但我的语法有问题。
Laser.swift中的函数是:
func shootLaser(_ sender: UITapGestureRecognizer, parentNode: SKNode, spriteNode: SKSpriteNode) {
let laser = SKSpriteNode(imageNamed: "laserBlast")
parentNode.addChild(laser)
laser.position = CGPoint(x: spriteNode.position.x, y: spriteNode.position.y)
}
GameScene
中的代码类似于......
class GameScene {
let tapRecognizer = UITapGestureRecognizer()
var laser = Laser()
override func didMove(to view: SKView) {
tapRecognizer.addTarget(self, action: #selector(GemScene.laser.shootLaser(_: , parentNode: self, spriteNode: main)))
}
这导致错误,“表达式列表中的预期表达式”,但所有表达式都在那里......不是吗?
答案 0 :(得分:2)
为什么不让自己更容易并为手势识别器创建单独的功能?
<choice>
<when expression="#[flowVars.IDRec.size() > 0]">
<logger level="INFO" message="Employee exists, #[payload]" />
</when>
<otherwise>
<logger level="INFO" message="Employee does not exist"/>
</otherwise>
</choice>
这也将简化override func didMove(to view: SKView) {
tapRecognizer.addTarget(self, action: #selector(tapRecognized))
}
func tapRecognized() {
laser.shootLaser(parentNode: self, spriteNode: main)
}
方法,不要求您传入手势识别器。