I have a node tree that looks like:
LayerWorld
-> layerBackground //contains the map tiles
-> layerUnitSurface //contains all the sprite nodes moving around the map
-> layerOverlay //contains the huds, UI buttons etc
Not sure if it's relevant, but I also control the positioning of some objects using .zPosition
according to the following defintions:
#define UNITLAYER_ZPOS_PASSENGER -10
#define UNITLAYER_ZPOS_GHOST 001
#define UNITLAYER_ZPOS_BACK 050
#define UNITLAYER_ZPOS_CITY 100
#define UNITLAYER_ZPOS_FRONT 200
#define UNITLAYER_ZPOS_SMOKE 300
#define UNITLAYER_ZPOS_BLAST 400
#define UNITLAYER_ZPOS_HUD 500
#define UILAYER_ZPOS_BUTTONS 1000
In a certain "inspection" mode where the user is focused on a particular sprite, I want to highlight the view. This unit is called the reconSprite
and is added to the layerUnitSurface
. I want to dim the entire background map except except for the sprite's immediate vicinity. SKLightNode
examples showing an illuminated character moving around a dark dungeon is exactly what I'm looking for.
I'm apparently applying the light node incorrectly as I never see any lighting changes in any of my layers. I don't see what I'm doing wrong, though:
layerBackground.lightingBitMask = 1;
layerBackground.shadowCastBitMask = 0;
layerBackground.shadowedBitMask = 1;
SKLightNode *intelLightSource = [[SKLightNode alloc] init];
intelLightSource.categoryBitMask = 1;
intelLightSource.falloff = 0.5;
intelLightSource.ambientColor = [SKColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:0.25];
intelLightSource.lightColor = [SKColor colorWithRed:0.8 green:0.8 blue:0.4 alpha:0.8];
intelLightSource.shadowColor = [SKColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.9];
intelLightSource.zPosition = UNITLAYER_ZPOS_SMOKE;
intelLightSource.position = reconSprite.position;
[layerWorld addChild:intelLightSource];
I expected this would make the entire map appear dim, with a bright region at reconSprite.position
. But, there's no visible changes. The entire scene remains fully illuminated.
I know the light source is present, because when I temporarily add:
reconSprite.lightingBitMask = 1;
reconSprite.shadowCastBitMask = 1;
reconSprite.shadowedBitMask = 1;
The reconSprite is brightened and casts a black shadow.
Question: why is my SKLightNode
affecting the reconSprite
but not the entire layerBackground
?