gpt4 book ai didi

ios - 从侧面生成敌人

转载 作者:行者123 更新时间:2023-11-28 08:43:37 28 4
gpt4 key购买 nike

我正在开发我的游戏,但是当我尝试从说我只能从场景的顶部和底部生成敌人时我遇到了一个问题,我不知道为什么

这是我的计时器:

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))

关于ios - 从侧面生成敌人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35848472/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com