当我运行这个函数时
func makeSpriteShoot(bullets bulletInfo:MHBulletInformation,player playerSprite:SKSpriteNode){
print("Foo")
let shootTimer = Timer.scheduledTimer(timeInterval: bulletInfo.frequency, target: true, selector: #selector(shootBullet), userInfo: nil, repeats: true)
}
func shootBullet(){
player.shootBullet(angle: 90)//player is a instance of a subclass of SKSpriteNode
}我得到以下exception+SIGABRT:
终止应用程序由于未识别的异常'NSInvalidArgumentException',原因:‘_ sent布尔shootBullet:未识别的选择器发送到实例.
上述两个函数都在运行在SKScene中的Swift3子类中。
值得注意的是,与#selector(test)不同,我没有收到任何编译时错误。
发布于 2016-11-19 04:40:13
您在使用target值设置Boolean时犯了错误。
target是在计时器触发时向其发送由aSelector指定的消息的对象。计时器保持对目标的强烈引用,直到它(定时器)失效为止。
因此,只需将target设置为self,如果在调度Timer的类中存在方法。
let shootTimer = Timer.scheduledTimer(timeInterval: bulletInfo.frequency, target: self, selector: #selector(shootBullet), userInfo: nil, repeats: true)https://stackoverflow.com/questions/40689232
复制相似问题