Я обнаружил, что это может быть связано с setScale
, я пробовал его с несколькими разными размерами, и земля не исчезает через несколько секунд, когда на 3.0-4.0,
, но эти масштабы слишком велики для игры , Мне нужно использовать setScale(1.0)
. Я проверял это много раз с разными размерами,
однако I setScale(1.0)
- это размер, который мне нужен для наземного спрайта.
Вот код:
func createGround() {
let groundTexture = SKTexture(imageNamed: "Ground")
groundTexture.filteringMode = .nearest
for _ in stride(from: 0, to: 2 + self.frame.size.width / groundTexture.size().width, by: 1) { //i
let ground = SKSpriteNode(texture: groundTexture)
ground.zPosition = -10
ground.anchorPoint = CGPoint(x:0.5,y:0.5)
ground.position = CGPoint(x: 0 - self.size.width / 2 + ground.size.width / 2, y: 0 - self.size.height / 2 + ground.size.height / 2)
ground.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: self.frame.size.width * 2.0, height: groundTexture.size().height / 1.0))
ground.setScale(1.0) //1.0 is the number I need however it disappears after a few seconds and the character falls and doesn't come back.
ground.physicsBody?.isDynamic = false
ground.physicsBody?.allowsRotation = false
ground.physicsBody?.affectedByGravity = false
ground.physicsBody?.usesPreciseCollisionDetection = true
ground.physicsBody!.categoryBitMask = groundCategory
ground.physicsBody!.contactTestBitMask = playerCategory | enemy1Category | enemy2Category | enemy3Category | enemy4Category | obstacleCategory | coinCatergory
// ground.physicsBody!.collisionBitMask = playerCategory | enemy1Category | enemy2Category | enemy3Category | enemy4Category | obstacleCategory | coinCatergory
ground.physicsBody!.collisionBitMask = 0 //tried with 0 and with catergories
ground.physicsBody?.restitution = 0.0
//ground.zPosition = 4.0 //see if zPosition makes the robot stay
// self.addChild(ground)
let moveLeft = SKAction.moveBy(x: -groundTexture.size().width, y: 0, duration: 7)
let moveReset = SKAction.moveBy(x: groundTexture.size().width, y: 0, duration: 0)
let moveLoop = SKAction.sequence([moveLeft, moveReset])
let moveForever = SKAction.repeatForever(moveLoop)
ground.run(moveForever)
self.addChild(ground)
}
}