0

How can I get the color value of a SKSpriteNode or SKTexture at a pixel offset?

let atlas = SKTextureAtlas(named: "SomeAtlas")
let texture = atlas.textureNamed("SomeTexture")
let node = SKSpriteNode(texture: texture)

// Something like this...    
let pixel: SKColor = node.pixelAtPoint(x: 30, y: 100)

If I were writing direct OpenGL I'd just load my texture into a framebuffer and use glReadPixels, but I can't seem to get that sort of low-level access in SpriteKit...

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
Doches
  • 3,276
  • 2
  • 19
  • 26

1 Answers1

0

I'm not sure you can read anything from the texture directly, but if you load the image as a UIImage first then you can read pixel values from that and also use it to create your sprite's textures. You could wrap it up in a subclass too to make things nicer.

GoatInTheMachine
  • 3,583
  • 3
  • 25
  • 35