SKSpriteNode照明不适用于SKTextureAtlas的纹理

Lea*_*s2D 6 lighting bump-mapping sprite-kit sktextureatlas sklightnode

我遇到了SpriteKit的问题(在OS X 10.11 beta上尝试过Xcode 7 beta和Xcode 6.4),如果我从图像创建SKTextureAtlas并且单独使用时可以正常工作的普通文件,那么法线贴图会崩溃.看这个例子:

在此输入图像描述

从左到右:

  • 具有纹理+正常+光照的精灵(来自atlas的纹理)
  • 纹理+正常的精灵(来自atlas的纹理)
  • 带纹理的精灵(来自atlas的纹理)
  • 具有正常纹理的精灵(来自atlas的纹理)
  • 具有纹理+正常+光照的精灵(通过imageNamed从单个文件创建的纹理:)

该图集是在运行时使用SKTextureAtlas atlasWithDictionary创建的:它包含以下纹理:

creating atlas with files: {
    "shield-normal.png" = "shield-normal.png";
    "shield.png" = "shield.png";
    "swords-normal.png" = "swords-normal.png";
    "swords.png" = "swords.png";
}
Run Code Online (Sandbox Code Playgroud)

注意:如果我在Xcode中创建Atlas并通过atlasNamed加载它,我会得到完全相同的问题: - 所以问题肯定不在于如何或何时创建地图集,而是因为纹理是从第一个地图集中获得的地点.

如果我使用单个文件创建精灵,则照明工作(最右边的图像):

tex = [SKTexture textureWithImageNamed:@"shield.png"];
normal = [SKTexture textureWithImageNamed:@"shield-normal.png"];
test2 = [SKSpriteNode spriteNodeWithTexture:tex normalMap:normal];
test2.position = CGPointMake(580, 400);
test2.lightingBitMask = 0xffffffff;
[self addChild:test2];
Run Code Online (Sandbox Code Playgroud)

我对atlas文件执行完全相同的操作,上面的屏幕截图证明我确实为精灵纹理获取了正确的图像(左起第3和第4个),并且从图集中获得正常的纹理.然而结果是左边的第一个图像,一个没有法线贴图的点亮的精灵.

我想知道,普通纹理是否需要一种SKTextureAtlas不适用的后处理形式?或者其他人在地图集中是否有正常纹理问题?

或许这可能是一个错误?


更新:我已在一个新的SpriteKit应用程序(OS X,在此下载并自行尝试)中使用以下代码重现此行为:

-(void)didMoveToView:(SKView *)view {
    SKLightNode* light = [SKLightNode node];
    light.position = CGPointMake(0, 0);
    [self addChild:light];

    id move1 = [SKAction moveByX:400 y:300 duration:3];
    id move2 = [SKAction moveByX:-400 y:-300 duration:3];
    id repeat = [SKAction repeatActionForever:[SKAction sequence:@[move1, move2]]];
    [light runAction:repeat];


    SKTexture* tex, *nor;
    SKSpriteNode* spr;
    {   // sprite with textures from individual files: lighting works
        tex = [SKTexture textureWithImageNamed:@"shield.png"];
        nor = [SKTexture textureWithImageNamed:@"shield-normal.png"];
        spr = [SKSpriteNode spriteNodeWithTexture:tex normalMap:nor];
        spr.position = CGPointMake(111, 111);
        spr.lightingBitMask = 0xffffffff;
        [self addChild:spr];
    }
    {   // sprite with textures from atlas: lighting does not work (no normal-map)
        SKTextureAtlas* atlas = [SKTextureAtlas atlasNamed:@"TicTac"];
        NSLog(@"atlas texture names: %@", atlas.textureNames);

        tex = [atlas textureNamed:@"shield.png"];
        nor = [atlas textureNamed:@"shield-normal.png"];
        spr = [SKSpriteNode spriteNodeWithTexture:tex normalMap:nor];
        spr.position = CGPointMake(222, 111);
        spr.lightingBitMask = 0xffffffff;
        [self addChild:spr];
    }
}
Run Code Online (Sandbox Code Playgroud)