player function
@objc func playerFunction(){
player = SKSpriteNode(imageNamed: "Player")
player.name = "Hero"
player.size = CGSize(width: 80, height: 80)
player.physicsBody = SKPhysicsBody(rectangleOf: player.size)
player.physicsBody?.affectedByGravity = false
player.physicsBody?.isDynamic = false
player.physicsBody?.allowsRotation = false
player.physicsBody!.categoryBitMask = 1
player.physicsBody!.collisionBitMask = 0
player.physicsBody!.contactTestBitMask = 2 | 5 | 6 | 7
player.physicsBody?.velocity.dx = 0
player.physicsBody?.velocity.dy = 0
player.zPosition = 1
player.position = CGPoint(x: self.frame.width / 2 - 700, y: self.frame.height / 2 - player.frame.height)
self.addChild(player)
}
platform method
@objc func platformFunction (){
platform_One = SKSpriteNode(imageNamed: "Platform")
platform_One.physicsBody = SKPhysicsBody(rectangleOf: platform_One.size)
platform_One.physicsBody?.affectedByGravity = false
platform_One.physicsBody?.isDynamic = false
platform_One.zPosition = 4
platform_One.position = CGPoint(x: 1 + self.frame.width / 2 - 570, y: self.frame.height / 2 - 260)
self.addChild(platform_One)
platform_Two = SKSpriteNode(imageNamed: "Platform")
platform_Two.physicsBody = SKPhysicsBody(rectangleOf: platform_Two.size)
platform_Two.physicsBody?.affectedByGravity = false
platform_Two.physicsBody?.isDynamic = false
platform_Two.physicsBody!.categoryBitMask = 7
platform_Two.physicsBody!.collisionBitMask = 1
platform_Two.physicsBody!.contactTestBitMask = 1
platform_Two.zPosition = 5
platform_Two.position = CGPoint(x: 1 + self.frame.width / 2 - 420, y: self.frame.height / 2 - 260)
self.addChild(platform_Two)
The player method and platform method code is added above and the player doesn't land on top of the platform instead the player goes through the platform even though the physics have been stated as above.