Reputation: 1332
I am loading a texture that is originally red for some of my sprites. However, I want to change that color to a white through my method loadPauseIcons():
func loadPauseIcons() {
let icons = ["HomeIcon", "LevelIcon", "RetryIcon"]
let iconSize = CGSize(width: pauseButton.size.width * 0.6, height: pauseButton.size.height * 0.6)
var iconY = pauseButton.position.y - pauseButton.size.height
for icon in icons {
let currentIcon = SKSpriteNode(imageNamed: icon)
currentIcon.position = CGPoint(x: pauseButton.position.x, y: iconY)
currentIcon.color = .white
currentIcon.size = iconSize
currentIcon.name = icon
currentIcon.zPosition = 11
iconY -= pauseButton.size.height * 0.35 + currentIcon.size.height
self.addChild(currentIcon)
pauseIcons.append(currentIcon)
}
}
This method is ran on the touchesBegan() method of an SKScene. However, I still get a red icon: (the house and the three bars)
Am I doing something wrong to change the color of my sprites?
Upvotes: 1
Views: 308
Reputation: 990
Try adding:
currentIcon.colorBlendFactor = 1.0
By default the colorBlendFactor
of a sprite is 0.0, which means that its color
property is ignored. The closer the value of colorBlendFactor
is to 1.0, the more of the sprite's color
property is applied.
Upvotes: 1