有人可以向我解释为什么我的节点的位置停留在原点。似乎只有375x667的设备在模拟器中运行此代码时,所有其他设备都存在此问题
//enemy
enemy.size = enemyTexture.size()
enemy.setScale(0.75)
enemy.zPosition = 2
enemy.position = CGPoint(x: 230, y: -40)
enemy.physicsBody = SKPhysicsBody(texture: enemyTexture, size: CGSize(width: enemy.size.width, height: enemy.size.height))
enemy.physicsBody!.isDynamic = false
enemy.physicsBody!.affectedByGravity = false
enemy.physicsBody!.categoryBitMask = CollisionNum.enemyNum.rawValue
enemy.physicsBody!.collisionBitMask = CollisionNum.swordNum.rawValue
enemy.physicsBody!.contactTestBitMask = CollisionNum.swordNum.rawValue
更新:(响应George_E_2)
if screenSize.height == 375{ //iphone X
bg.size = CGSize(width: 812, height: 375)
enemy.size = enemyTexture.size()
enemy.setScale(0.75)
enemy.position = CGPoint(x: 230, y: -40)
enemy.physicsBody = SKPhysicsBody(texture: enemyTexture, size: CGSize(width: enemy.size.width, height: enemy.size.height))
enemy.physicsBody!.isDynamic = false
enemy.physicsBody!.affectedByGravity = false
enemy.physicsBody!.categoryBitMask = CollisionNum.enemyNum.rawValue
enemy.physicsBody!.collisionBitMask = CollisionNum.swordNum.rawValue
enemy.physicsBody!.contactTestBitMask = CollisionNum.swordNum.rawValue
为了支持其他设备,我首先检查了用户正在使用的设备,然后将位置放在该设备上。我对SpriteKit和Swift相当陌生,所以我认为手动输入坐标会更好一些。例如,使用我用于iphone X的代码,一切都可以正确缩放和放置,但是对于分辨率为375X667的任何设备,所有节点都放置在原点