3

I'm playing around with SKLightNode. I'm trying to create shadows so that it would look like the sun is at noon. So basically something like this:

enter image description here

However all I can get SKLightNode to render for me is this:

enter image description here

So the problem is that it looks like the light is coming from right next to the object and from the same level.

I have played around with the SKLightNode configuration but this is what I have for the moment (I've tried many configurations that don't seem to have any effect)

   var light = SKLightNode()
    //testing lightnodes
    light.name = "light"
    light.categoryBitMask = 3
    light.position = point
    light.zPosition = 100.0
    light.falloff = 100.00;
    light.enabled = true
    light.lightColor = UIColor(red:  86/255, green: 128/255, blue: 45/255, alpha: 0.5) //initWithRed:1.0 green:1.0 blue:0.0 alpha:0.5];
    light.shadowColor = UIColor(red:  220/255, green: 220/255, blue: 220/255, alpha: 0.3)//[[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.3];
    light.ambientColor = UIColor(red:  220/255, green: 220/255, blue: 220/255, alpha: 0.3)//[[UIColor alloc] initWithRed:0.0
    addChild(light)
user3673836
  • 591
  • 1
  • 9
  • 23

1 Answers1

1

You can't achieve the effect you want with SKLightNode. Remember that SK is a 2D platform. Your desired effect is 3D. You can probably achieve the effect you want by adding a child to your node with a position offset and custom alpha settings.

sangony
  • 11,636
  • 4
  • 39
  • 55
  • Thanks for your input Sangony! Could you elaborate a bit further what you mean? – user3673836 Mar 08 '15 at 02:03
  • @user3673836 - Elaborate on what? – sangony Mar 08 '15 at 03:47
  • I mean I'm quite new to Swift and sprite-kit so I might be asking stupid, but what was your idea with "a position offset and custom alpha settings" in more detail? Especially how would the shadow follow the direction of the ball? – user3673836 Mar 08 '15 at 06:41
  • @user3673836 - I'm not versed in Swift but I'm sure you know how to add a child to a SKSpriteNode. If not just do a search and you will find how. As for the alpha settings, you can use a copy of your image and set the alpha property to something like 0.3 to make it somewhat transparent. If you want the edges to be more transparent, you can create that effect effect in an image editing application like Photoshop or FireWorks. – sangony Mar 08 '15 at 13:38