Reputation: 695
I have been changing SKSpriteNode colour and size within didBeginContact in the following way, using an SKTexture.
if firstBody.categoryBitMask == spriteCategory && secondBody.categoryBitMask == enemyCategory {
var newSprite = firstBody.node
let newImage = SKTexture(imageNamed: "newSprite.png")
(newSprite as? SKSpriteNode)?.size = newImage.size() //magic
oldToNewSpriteAction = SKAction.setTexture(newImage)
newSprite!.runAction(oldToNewSpriteAction)
}
Now I am creating a sample code without SKTextures, setting my SKSpriteNodes in the following way:
oldSprite = SKSpriteNode(color: SKColor.blueColor(), size: oldSpriteSize)
newSprite = SKSpriteNode(color: SKColor.BrownColor(), size: newSpriteSize)
How can I change the sprite colour and size within didBeginContact without SKTextures?
Upvotes: 5
Views: 4682
Reputation: 570
This should work
newSprite.color = UIColor.redColor()
newSprite.size = CGSize(width: 250, height: 250)
Upvotes: 2