خرید بک لینک

Vote count: 0

I want to create a series of different color sprites using a single gray scale image:

enter image description here

For example, if I use blue color with blendingMode: .Color in a software (Sketch, AI, etc), I get:

enter image description here

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:

enter image description here

Definitely not what I want.

When I change the color blend mode to .Multiply I got this:

enter image description here

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:

enter image description here

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!

asked 29 secs ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 29 فروردين 1395 ساعت: 3:46

صفحه بندی