1

My light:

self.light = [[SKLightNode alloc] init];
self.light.categoryBitMask = 0;
self.light.falloff = 1;
self.light.ambientColor = [UIColor whiteColor];
self.light.lightColor  = [[UIColor alloc] initWithRed:1.0 green:1.0 blue:0.0 alpha:0.5];
self.light.shadowColor = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.3];
self.light.zPosition = 200;
[self.world addChild:self.light];

On Update I change light position to character position.

I tried everything and just can't see my light.

HelloimDarius
  • 695
  • 5
  • 23

1 Answers1

1

Adding a light to a scene doesn't add a white circle, a light-bulb, or something like that to the scene, it just illuminates everything with that light. So you will not "see the light", just its effects.

If you want to see the shadows the light casts, you have to activate the shadows for each object that must cast shadows. You can do this for your SKNode with:

yourSKNode.shadowCastBitMask = 1

Finally, if you want to make a bump effect on something like a background, you must create the background using:

let background = SKSpriteNode(imageNamed: "theName", normalMapped: true)
background.lightingBitMask = 1
RoberRM
  • 883
  • 9
  • 18
  • But how would I add something like a light-bulb effect? – HelloimDarius Oct 22 '15 at 09:48
  • If you want to see something where the light is, you'll have to add a SKNode at that point yourself (for example, you could add a SKSpriteNode with a light-bulb texture or a SKEmitterNode emitting fire cells). Is that what you were looking for? – RoberRM Oct 22 '15 at 16:07
  • What i'm trying to achieve here is to make a dungeon-crawler type game, where character has it's light (like a spotlight) and while player is walking nearby map gets light and other places would be dark. I tried adding a transparent texture but i'd like light to be more dynamic. – HelloimDarius Oct 22 '15 at 17:08
  • Ah! Then you should use both your method and mine: yours to emulate the visual effect (create something to see on the scene) and mine to create the shadows that light would make with the objects in your scene. The SKLightNode is only good for creating dynamic shadows, it does not create a volumetric or spatial representation of the light. Sorry! – RoberRM Oct 22 '15 at 17:35
  • please take a look at this [link](https://www.youtube.com/watch?v=HWYW6U__v6g). Can I make effect similiar to this using shadows? – HelloimDarius Oct 22 '15 at 18:52
  • Thanks. I got a light! :))) – HelloimDarius Oct 22 '15 at 19:38
  • I'm glad to hear it! Good luck on your game! :) – RoberRM Oct 23 '15 at 00:47