我一直没有得到一个SKSpriteNode投阴影,也是消失时,进入阴影从同一个光源。我能做到这两种中的一种,但不能两者兼得。
根据docs:,如果精灵在光线投射的阴影中,而精灵的z位置比光低,那么阴影会影响精灵的照明方式。所有这些我都做过。我的SKLightNode的zPosition为100,所有其他节点的zPositions都较低。
我尝试过lightingBitMask、shadowCastBitMask和shadowedBitMask设置的任何和所有组合,但都没有效果。
我张贴的孤立代码,重新创建我的问题。蓝色的盒子投下阴影,但没有被墙壁的阴影所覆盖。紫色的盒子没有阴影,而是被墙壁的阴影所覆盖。
光线对触摸动作有反应,所以可以自由地在屏幕周围移动。该项目处于景观模式。
我少了什么或者没看到什么?
#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发布于 2015-03-28 00:49:13
我刚刚收到苹果开发者技术支持部门的回复,确认这是SpriteKit (SKLightNode)中的一个bug。目前,他们不知道这个问题的解决办法,但将更新我,如果找到一个。
根据他们的要求,我已经提交了一份错误报告。
更新2015年4月22日
SK工程证实,SpriteKit不支持阴影投射和阴影在同一物体上。目前还没有解决办法。这一问题将在某一时刻得到解决。
更新2015年12月15日
苹果公司就这一问题做出了新的回应。
苹果开发者关系部14-2015年12月01:35 没有解决这一问题的计划。 我们现在结束这份报告。
发布于 2015-04-23 10:53:31
我找到了一些解决办法(不确定它对所有情况都有用,但在某些情况下):你可以制造两个(或更多)不同的光源,然后一个接一个地(或通过一些组)分配给你的精灵。那么阴影就会根据我们的需要结合起来--正确。
SKLightNode* light1 = [SKLightNode new];
SKLightNode* light2 = [SKLightNode new];
... // init them equally
light1.categoryBitMask = 1;
light2.categoryBitMask = 2;
...
SKSpriteNode* sprite1 = ...
SKSpriteNode* sprite2 = ...
sp1.shadowCastBitMask = 1;
sp1.shadowedBitMask = 1;
sp2.shadowCastBitMask = 2;
sp2.shadowedBitMask = 2;https://stackoverflow.com/questions/28662600
复制相似问题