SKLightNode 投射阴影问题 [英] SKLightNode cast shadow issue
问题描述
我没有成功让 SKSpriteNode 投射阴影,并且在从同一光源进入阴影时也会消失.我可以做两者之一,但不能同时做.
I have been unsuccessful in getting a SKSpriteNode to cast a shadow AND also be made to disappear when going into a shadow from the same light source. I am able to do one of the two but not both.
根据文档:如果精灵位于灯光投射的阴影内,并且精灵的 z 位置低于灯光,则阴影会影响精灵的照明方式.所有这些我已经做好了.我的 SKLightNode 的 zPosition 为 100,所有其他节点的 zPositions 都较低.
According to the docs: If the sprite is inside a shadow cast by a light and the sprite has a lower z position than the light, the shadow affects how the sprite is lit. All of which I have done. My SKLightNode has a zPosition of 100 and all other nodes have lower zPositions.
我已经尝试了用于 lightingBitMask、shadowCastBitMask 和 shadowedBitMask 的任何和所有设置组合,但没有任何效果.
I have tried any and all combinations of settings for lightingBitMask, shadowCastBitMask and shadowedBitMask but nothing has worked.
我正在发布重新创建我的问题的隔离代码.蓝色框投下阴影,但未被墙壁阴影覆盖.紫色的盒子没有投下阴影,被墙壁阴影覆盖.
I am posting the isolated code which recreates my issue. The blue box casts a shadow but is not covered by the wall shadow. The purple box casts no shadow and is covered by the wall shadow.
灯光会响应触摸移动,因此您可以随意在屏幕上移动它.项目处于横向模式.
The light responds to touch movement so feel free to move it around the screen. The project is in landscape mode.
我错过了什么或没有看到什么?
What am I missing or not seeing?
#import "GameScene.h"
@implementation GameScene {
SKSpriteNode *lightBulb;
}
-(void)didMoveToView:(SKView *)view {
typedef NS_OPTIONS(uint32_t, Level1LightCategory)
{
CategoryLightPlayer = 1 << 0,
};
SKSpriteNode *worldNode = [SKSpriteNode spriteNodeWithColor:[SKColor clearColor] size:CGSizeMake(1136, 640)];
worldNode.zPosition = 10;
//worldNode.position = CGPointMake(self.size.width/2, self.size.height/2);
[self addChild:worldNode];
lightBulb = [SKSpriteNode spriteNodeWithColor:[SKColor yellowColor] size:CGSizeMake(20, 20)];
lightBulb.zPosition = 100;
lightBulb.position = CGPointMake(50, 50);
[worldNode addChild:lightBulb];
SKLightNode *light = [[SKLightNode alloc] init];
//light.zPosition = 100; // <- tried setting this again but to no effect
light.categoryBitMask = CategoryLightPlayer;
light.falloff = 0.3;
light.ambientColor = [UIColor whiteColor];
light.lightColor = [[UIColor alloc] initWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
light.shadowColor = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
[lightBulb addChild:light];
SKSpriteNode *wall = [SKSpriteNode spriteNodeWithColor:[SKColor redColor] size:CGSizeMake(10, 300)];
wall.zPosition = 50;
wall.position = CGPointMake(500, 200);
wall.lightingBitMask = CategoryLightPlayer;
wall.shadowCastBitMask = CategoryLightPlayer;
wall.shadowedBitMask = 0x00000000;
[worldNode addChild:wall];
SKSpriteNode *box0 = [SKSpriteNode spriteNodeWithColor:[SKColor blueColor] size:CGSizeMake(30, 30)];
box0.zPosition = 40;
box0.position = CGPointMake(800, 200);
box0.lightingBitMask = CategoryLightPlayer;
box0.shadowCastBitMask = CategoryLightPlayer;
box0.shadowedBitMask = CategoryLightPlayer;
[worldNode addChild:box0];
SKSpriteNode *box1 = [SKSpriteNode spriteNodeWithColor:[SKColor purpleColor] size:CGSizeMake(30, 30)];
box1.zPosition = 40;
box1.position = CGPointMake(800, 300);
box1.lightingBitMask = CategoryLightPlayer;
//box1.shadowCastBitMask = CategoryLightPlayer;
//box1.shadowedBitMask = CategoryLightPlayer;
[worldNode addChild:box1];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self.scene];
lightBulb.position = touchLocation;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self.scene];
lightBulb.position = touchLocation;
}
-(void)update:(CFTimeInterval)currentTime {
//
}
@end
推荐答案
我刚刚收到 Apple 开发人员技术支持的回复,确认这是 SpriteKit (SKLightNode) 中的一个错误.目前他们不知道解决此问题的方法,但如果找到,他们会通知我.
I just heard back from Apple Developer Technical Support confirming this is a bug in SpriteKit (SKLightNode). Currently they do not know of a workaround for this issue but will update me if one is found.
根据他们的要求,我已经提交了错误报告.
As per their request, I have filed a bug report.
2015 年 4 月 22 日更新
SK 工程确认 SpriteKit 不支持阴影投射和阴影在同一对象上.目前没有解决方法.这个问题将在某个时候得到解决.
SK engineering confirmed that SpriteKit doesn't support shadow casting and shadowed on the same object. There is no workaround at present. This issue will be addressed at some point.
2015 年 12 月 15 日更新
收到 Apple 关于此问题的新回复.
Received a new response from Apple regarding this issue.
Apple 开发者关系 2015 年 12 月 14 日下午 1:35
Apple Developer Relations 14-Dec-2015 01:35 PM
没有计划解决这个问题.
There are no plans to address this.
我们现在关闭此报告.
这篇关于SKLightNode 投射阴影问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!