Andr3wz
Andr3wz

Reputation: 11

SKSpriteNode creates a thin coloured line

So I am using 3 SKSpriteNode's in my application. floorSprite, leftWall and rightWall.

This is the code I am currently using:

    let floorSprite = SKSpriteNode()//(imageNamed: "floor")
    floorSprite.alpha = 0.0
    floorSprite.anchorPoint = CGPoint(x: 0.5, y: CGPoint.zero.y)
    floorSprite.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: self.frame.size.width, height: floorSprite.size.height + 12))
    floorSprite.physicsBody?.isDynamic = false
    floorSprite.physicsBody?.restitution = 0.4
    floorSprite.position = CGPoint(x: self.frame.minX, y: self.frame.minY + (floorSprite.size.height / 2))
    floorSprite.physicsBody?.contactTestBitMask = 0x1 << 1
    floorSprite.physicsBody?.collisionBitMask = 0x1 << 1
    floorSprite.zPosition = 4
    floorSprite.aspectFillToSize(self.frame.size)
    self.addChild(floorSprite)
    self.floorSprite = floorSprite
    
    let leftwall = SKSpriteNode()
    leftwall.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 0.1, height: self.frame.size.height*2))
    leftwall.physicsBody?.collisionBitMask = 0x1 << 1
    leftwall.physicsBody?.isDynamic = false
    leftwall.position = CGPoint(x: 0 , y: self.frame.size.height / 2.0)
    leftwall.zPosition = 4
    leftwall.physicsBody?.restitution = 1.0
    self.addChild(leftwall)
    
    let rightwall = SKSpriteNode()
    rightwall.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 0.1, height: self.frame.size.height*2))
    rightwall.physicsBody?.collisionBitMask = 0x1 << 1
    rightwall.physicsBody?.isDynamic = false
    rightwall.physicsBody?.restitution = 1.0
    rightwall.position = CGPoint(x: self.frame.size.width , y: self.frame.size.height / 2.0)
    rightwall.zPosition = 4
    self.addChild(rightwall)

Here is a screenshot of the issue I have. You can see the light blue lines that shows. If I remove the self.addChild line, the Sprite is not there, and the light blue color gone. CLICK HERE FOR IMAGE.

Any ideas what might be wrong here? I have tried adding leftWall.isHidden = true and leftWall.alpha = 0.0 but that has no effect...

Upvotes: 1

Views: 36

Answers (1)

Fluidity
Fluidity

Reputation: 3995

This looks like you have SKScene.showPhysics on.. turn this off in your appdelegate (or didmovetoview) or wherever you turned it on, and the lines should go away.

These are caused by your physics bodies :)

Upvotes: 1

Related Questions