【问题标题】:SKSpriteNode creates a thin coloured lineSKSpriteNode 创建一条细的彩色线
【发布时间】:2017-01-31 21:32:00
【问题描述】:

所以我在我的应用程序中使用了 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 但这没有任何效果...

【问题讨论】:

  • 你有.showsPhysics = true 在附加到场景的视图上吗?
  • @RezaShirazian 你是救生员。删除该行,现在一切正常,谢谢! :)

标签: ios swift xcode sprite-kit skspritenode


【解决方案1】:

这看起来像你打开了SKScene.showPhysics..在你的appdelegate(或didmovetoview)或你打开它的任何地方关闭它,线条应该消失。

这些是由你的物理体造成的 :)

【讨论】:

    猜你喜欢
    • 2011-03-02
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    相关资源
    最近更新 更多