【发布时间】:2016-04-27 23:19:33
【问题描述】:
我正在创建一个游戏,但我的子弹生成方法与操纵杆相关联时不断收到此错误。我想在操纵杆处于活动状态时重复生成节点这是我创建触发方法的方式
override func didMoveToView(view: SKView) {
if fireWeapon == true {
NSTimer.scheduledTimerWithTimeInterval(0.25, target: self,
selector: Selector ("spawnBullet1"), userInfo: nil, repeats: true)
}
}
func spawnBullet1(){
self.addChild(bullet1)
bullet1.position = CGPoint (x: hero.position.x , y:hero.position.y)
bullet1.xScale = 0.5
bullet1.yScale = 0.5
bullet1.physicsBody = SKPhysicsBody(rectangleOfSize: bullet1.size)
bullet1.physicsBody?.categoryBitMask = PhysicsCategory.bullet1
bullet1.physicsBody?.contactTestBitMask = PhysicsCategory.enemy1
bullet1.physicsBody?.affectedByGravity = false
bullet1.physicsBody?.dynamic = false
}
override func touchesBegan(touches: Set<UITouch>, withEvent
event:UIEvent?) {
for touch in touches {
let location = touch.locationInNode(self)
let node = nodeAtPoint(location)
if (CGRectContainsPoint(joystick.frame, location)) {
stickActive = true
if stickActive == true {
fireWeapon = true
}
第一个项目符号按计划启动并且效果很好但是,每次第二个项目符号启动应用程序时都会崩溃并且我收到错误消息。有人可以告诉我另一种创建射速的方法
【问题讨论】:
-
您需要在发射下一个子弹之前移除子弹1,或者每次都创建新子弹。
-
告诉我们变量 bullet1 的创建位置
-
你说创建@MateHegedus是什么意思
-
变量bullet1在哪里声明??
-
在 NSTimer 方法中@mateHegedus 我也尝试了一个不起作用的运行块方法
标签: swift sprite-kit game-physics skspritenode