Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sprite Kit iOS 7 - how to add a shadow to a SKSpriteNode?

I have a SKSpriteNode containing other SKSpriteNodes. How can I create a copy of this SKSpriteNode where all the pixels are black?

Once I have this shadow SKSpriteNode I will then flip it upside down and use it as a shadow.

Thanks

like image 890
Newt-7 Avatar asked Sep 27 '14 08:09

Newt-7


1 Answers

You can create a shadow using the same image like this :

SKSpriteNode *shadow = [SKSpriteNode spriteNodeWithImageNamed:@"YourImageName"];

shadow.blendMode = SKBlendModeAlpha;
shadow.colorBlendFactor = 1;
shadow.color = [SKColor blackColor];
shadow.alpha = .25;  // make shadow partly transparent

Then just position it however you like based on desired light direction. Alpha isn't needed if you want it to be solid black.

like image 121
prototypical Avatar answered Sep 20 '22 00:09

prototypical