SKSpriteNode创建一条细彩色线条

时间:2017-01-31 21:32:01

标签: ios swift xcode sprite-kit skspritenode

所以我在我的申请中使用了3 SKSpriteNodefloorSpriteleftWallrightWall

这是我目前使用的代码:

    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)

以下是我遇到的问题的屏幕截图。你可以看到显示的浅蓝色线条。如果我删除self.addChild行,则Sprite不存在,浅蓝色消失。 CLICK HERE FOR IMAGE.

任何想法在这里可能有什么问题?我尝试添加leftWall.isHidden = trueleftWall.alpha = 0.0,但这没有效果......

1 个答案:

答案 0 :(得分:1)

这看起来好像你有SKScene.showPhysics ..在你的appdelegate(或者你移动到视图)或你打开它的任何地方关闭它,并且线条应该消失。

这些是由您的物理机构引起的:)