2

I have been developing my application and testing using the iPhone 11 Pro simoulator and everything has been working as designed. When I switched to an iPhone 11 regular or older model I get an error, 2020-04-11 12:15:44.172116-0400 NinjaEscape[98021:3425018] PhysicsBody: Could not create physics body. IT works fine on 11 pro or iPad. This only happens to my players physics body. The rest of the bodies are created without an issue.

Here is function for creating my player:

 func createPlayer(){
    let playerTexture = SKTexture(imageNamed:"NinjaR_1")
    player = SKSpriteNode(texture: playerTexture)
    player.zPosition = 10
    player.position = CGPoint(x: frame.width/2.5, y: frame.height * 0.30)
    player.setScale(2)
    player.texture?.size()

    player.physicsBody = SKPhysicsBody(texture: player.texture!, size: player.frame.size)
    player.physicsBody?.contactTestBitMask = 1
    player.physicsBody?.isDynamic = true
    player.physicsBody?.categoryBitMask = 7
    player.physicsBody?.collisionBitMask = 5 // 2 | 3
    player.physicsBody?.allowsRotation = false
    player.physicsBody?.usesPreciseCollisionDetection = true

    addChild(player)
Alucard
  • 35
  • 4
  • Try replacing `player.frame.size` with `playerTexture.size()` – Xcoder Apr 11 '20 at 16:35
  • I have tried that, still get the error. I deleted the images and re added them. I also tried resizing the image manually and not scaling it. tried renaming the images and adding them again. read somewhere to restart my computer, tried that as well. – Alucard Apr 11 '20 at 16:47
  • now the bug has spread to the iPhone 11 Pro max simulator which is the only one that was working. – Alucard Apr 11 '20 at 16:52
  • Possibly related to the bug discussed in this or in other threads: https://stackoverflow.com/questions/59961842/physicsbody-could-not-create-physics-body/60016825#60016825 TL;DR Physics bodies from textures may not work correctly, with the exact circumstances of failure depending on the iOS version for 13.0 and later. The problem may appear only on real devices (at least I never ran into it using the simulator). – bg2b Apr 11 '20 at 17:07

0 Answers0