我正在創建一款遊戲,並且我正在嘗試創建一種拍攝方法。我把子彈產生在一把槍上,並沿着操縱桿的方向移動。這裏是我如何以一致的速度(火速)產生子彈並向着操縱桿的方向移動。如何在按鈕激活的情況下重複產生SKnode
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
}
此方法僅在啓動第二個應用程序崩潰之前啓動第一個項目符號。所有的子彈運動都是完美的,只是產生了一串子彈射擊。我想不出一種可以創造火速的替代方法。
當它崩潰時,會收到什麼錯誤消息? –
另外,什麼是bullet1變量? –
它說,類似。錯誤崩潰,試圖添加已經有父母的SkSpritenode「通常會發生什麼,當你調用相同的self.addchild兩次@mate Hegedus – gkolman