我正在进行我的游戏,但当我试图从上面和下面的场景中产生敌人时,我面临一个问题我不知道为什么
这是我的计时器:

override func didMoveToView(view: SKView) {
    initialzeGame()
    NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("spawnEnemy"), userInfo: nil, repeats: true)
}

剩下的就是:
func randomBetweenNumbers(firstNum: CGFloat, secondNum: CGFloat) -> CGFloat {
    return CGFloat(arc4random()) / CGFloat(UINT32_MAX) * abs(firstNum + secondNum) + min(firstNum, secondNum)
}

func spawnEnemy() {
    //supposed to pick random point within the screen width

    let Pos = randomBetweenNumbers(0, secondNum: frame.height )
    //let PosTwo = randomBetweenNumbers(0, secondNum: frame.height )

    let enemy = SKSpriteNode(imageNamed: "zombie") //create a new enemy each time
    enemy.position = CGPointMake(CGFloat(Pos), self.frame.size.width/16)
    enemy.physicsBody = SKPhysicsBody(circleOfRadius: 7)
    enemy.physicsBody?.affectedByGravity = true
    enemy.physicsBody?.categoryBitMask = 0
    enemy.physicsBody?.contactTestBitMask = 1
    enemy.size = CGSize(width: 80, height: 70)
    let enmyact = SKAction.moveTo(hero.position, duration: 2)
    enemy.runAction(enmyact)
    addChild(enemy)
}

最佳答案

反转CGPointMake中的参数。

  enemy.position = CGPointMake(self.frame.size.width/16, CGFloat(Pos))

10-07 16:19
查看更多