SKSpriteNode lighting does not work with textures from SKTextureAtlas

I ran into a problem with SpriteKit (I tried Xcode 7 beta and Xcode 6.4 on the beta version of OS X 10.11) when the normal display breaks if I create SKTextureAtlas from an image and regular files that work when used separately. See this example:

enter image description here

From left to right:

  • Sprite with texture + normal + lighting (texture from satin)
  • Sprite with texture + normal (texture from satin)
  • Texture sprite (satin texture)
  • Sprite with normal texture (satin texture)
  • Sprite with texture + normal + lighting (textures created from separate files using imageNamed :)

The atlas is created at runtime using SKTextureAtlas atlasWithDictionary: and it contains the following textures:

creating atlas with files: { "shield-normal.png" = "shield-normal.png"; "shield.png" = "shield.png"; "swords-normal.png" = "swords-normal.png"; "swords.png" = "swords.png"; } 

Note. I get the same problem if I create the Atlas in Xcode and load it through atlasNamed: - therefore, the problem is definitely not how and when the atlas is created, but because the textures are obtained from the atlas in the first place.

If I create a sprite with separate files, then lighting works (the rightmost image):

 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]; 

I do the same with the atlas files, and the screenshot above proves that I get the correct images (3rd and 4th on the left) for the sprite textures and normal ones like the textures from the atlas. However, the result is the first image on the left, the illuminated sprite without a normal display.

Interestingly, normal textures require a post-processing form, what does SKTextureAtlas not apply? Or did anyone else have problems with normal textures in the atlas?

Or maybe it could be a mistake?


Update: I reproduced this behavior in a new SpriteKit application (OS X, download it here and try it yourself ) with the following code:

 -(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]; } } 
+6
source share

All Articles