Search code examples
iosswiftsprite-kitskshapenode

Why are SKShapeNode brighter on the top border


Im just want to know why these SKShapeNode are behaving this way. I tried setting sprite.lineWidth and sprite.glowWidth to 0 but can't get them to display evenly. However this doesn't happen when having them all display using UIColor.redColor().

Also on another note, you can't really see the effect on these pictures but when I simulate them on my iPhone, the colors don't 'blend' properly. It's difficult to see on darker colors and easier on contrasting colors i.e red and yellow.

enter image description here enter image description here

You can see the top borders are slightly brighter than the bottom and hence can clearly distinguish the boxes. How do I make them appear "smoother"? This is the code Im using:

    var x: CGFloat = 0.0
    var skip: CGFloat = 10
    var randR: CGFloat = 242
    var randG: CGFloat = 218
    var randB: CGFloat = 242

    class GameScene: SKScene {
override func didMoveToView(view: SKView) {
    /* Setup your scene here */

}

func randomColor() -> CGFloat {

    return (CGFloat(arc4random_uniform(255)))

}


override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
   /* Called when a touch begins */

    let spriteHeight: CGFloat = 50.0


    for touch in touches {
        let location = CGPoint(x: (CGRectGetMidX(self.frame)), y: (CGRectGetMinY(self.frame) + CGFloat(spriteHeight * x)))
        let sprite = SKShapeNode(rectOfSize: CGSizeMake((self.frame.width), 50))
        //sprite.fillColor = UIColor.redColor()
        sprite.position = location
        sprite.lineWidth = 0
        //sprite.glowWidth = 0
        randR = randR - skip
        randG = randG - skip
        randB = randB - skip
        sprite.fillColor = UIColor(red: CGFloat((randR)/256), green: CGFloat((randG)/256), blue: CGFloat((randB)/256), alpha: 1.0)
        x++
        self.addChild(sprite)
    }
}

Solution

  • What you are seeing is not "real". Measure the color values and you will see that what you are observing is not objective reality, but a manifestation of your brain trying to make sense of the world.

    https://en.wikipedia.org/wiki/Mach_bands