I'm having a problem when creating an SKSpriteNode from pixelData.
Below is my code.
var pixelData: [UInt32] = [UInt32](count: 256, repeatedValue: 0xff0000ff)
pixelData.appendContentsOf([UInt32](count: 256, repeatedValue: 0xff00ff00))
pixelData.appendContentsOf([UInt32](count: 256, repeatedValue: 0xffff0000))
pixelData.appendContentsOf([UInt32](count: 256, repeatedValue: 0x000000ff))
let data = NSData(bytes: pixelData, length: pixelData.count * sizeof(UInt32))
let texture = SKTexture(data: data, size: CGSize(width: 32, height: 32))
let node = SKSpriteNode(texture: texture, size: CGSize(width: 32, height: 32))
node.position.x = self.frame.midX
node.position.y = self.frame.midY
self.addChild(node)
It went as I wish for the three bottom rows (which is the first 3 parts in the pixelData array, 0xff0000ff
, 0xff00ff00
, 0xffff0000
: Red, Green, and Blue).
However, I expected the top row to be totally transparent: 0x000000ff
, which should mean rgba(1, 0, 0, 0). But it appeared as this:
I don't know why this happen. Is my understanding of pixelData wrong? Or is it a bug or something in SpriteKit?
Thank you very much for your help!