I want to create a series of different color sprites using a single gray scale image:
For example, if I use blue color with blendingMode: .Color in a software (Sketch, AI, etc), I get:
Then I create a subclass of SKSpriteNode, use init method like this:
init() {
let image = UIImage(named: "gem1")
// let image = UIImage(named: "gem1")?.imageWithRenderingMode(.AlwaysTemplate)
let coloredImage = image?.blendColored(someColor, blendMode: .Color)
let texture = SKTexture(image: coloredImage!)
super.init(texture: texture, color: UIColor.clearColor(), size: texture.size())
}
But I get the sprite like this:
Definitely not what I want.
When I change the color blend mode to .Multiply I got this:
Still not what I want.
I also tried use the tint color method:
init() {
let image = UIImage(named: "gem1")
let texture = SKTexture(image: image!)
// let texture = SKTexture(image: coloredImage!)
super.init(texture: texture, color: UIColor.clearColor(), size: texture.size())
self.color = color
self.colorBlendFactor = 1.0
}
The result is:
No ugly edges, but the color is not what I want, because if I directly set the color of sprite to be blue, I caot choose color blend mode there.
So the problem is: How can I write init method for a subclass of SKSpriteNode, such that I can use a gray scale image as texture, and choose whatever color blend mode I want, without any edge issue?
Thanks!





