0

我试图在我的游戏中放置一个矩形,但它没有出现。这是我声明它和其他重要变量的地方。

    var rect1: SKShapeNode! = SKShapeNode()
    var blackColor = (SKColor(red:0.00, green:0.00, blue:0.00, alpha:1))
    var screenWidth: CGFloat! = 0
    var screenHeight: CGFloat! = 0

这就是我赋予它属性的地方。

            if screenWidth == 1024{
        rect1 = SKShapeNode(rectOfSize: CGSizeMake(screenWidth/50, screenWidth/23))
    }else if screenWidth == 568 || screenWidth == 480{
        rect1 = SKShapeNode(rectOfSize: CGSizeMake(screenWidth/50, screenWidth/23))
    }else{
        rect1 = SKShapeNode(rectOfSize: CGSizeMake(screenWidth/50, screenWidth/23))
    }

    rect1.fillColor = blackColor
    rect1.alpha = 0
    rect1.physicsBody?.dynamic = false
    rect1.physicsBody?.categoryBitMask = PhysicsCategory.rect1
    rect1.physicsBody?.contactTestBitMask = PhysicsCategory.ball
    rect1.physicsBody?.collisionBitMask = PhysicsCategory.None
    rect1.physicsBody?.usesPreciseCollisionDetection = true
    rect1.position = CGPoint(x: 924.325, y: 678.42)
    self.addChild(rect1)

没有错误,但没有显示矩形。任何帮助,将不胜感激。

4

1 回答 1

3

alpha=0 表示它是完全透明的。我想这就是你看不到它的原因。

于 2015-03-05T06:47:01.483 回答