Skip to content

Commit b57f392

Browse files
author
Thayer J Andrews
committed
CCSprite - Fix texture coordinate setup from normal map sprite frame
If a sprite has a normal map but not a texture, we want to set up the texture rect from the normal map. This was mostly implemented but because [setTextureRect: ...] referenced self.texture it was broken. Instead of referencing self.texture in this case you need to reference the normal map texture. Fix this by refactoring the guts of [setTextureRect: ...] into [setTextureRect: forTexture: ...] which takes the texture to use as a parameter instead of always using self.texture. Calls to the original [setTextureRect: ...] just call through to [setTextureRect: forTexture: ...] supplying self.texture as the texture parameter.
1 parent 0764bd1 commit b57f392

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cocos2d/CCSprite.m

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,18 @@ -(void) setTextureRect:(CGRect)rect
239239

240240
-(void) setTextureRect:(CGRect)rect rotated:(BOOL)rotated untrimmedSize:(CGSize)untrimmedSize
241241
{
242-
_textureRectRotated = rotated;
242+
[self setTextureRect:rect forTexture:self.texture rotated:rotated untrimmedSize:untrimmedSize];
243+
}
243244

245+
- (void)setTextureRect:(CGRect)rect forTexture:(CCTexture*)texture rotated:(BOOL)rotated untrimmedSize:(CGSize)untrimmedSize
246+
{
247+
_textureRectRotated = rotated;
248+
244249
self.contentSizeType = CCSizeTypePoints;
245250
[self setContentSize:untrimmedSize];
246251
_textureRect = rect;
247252

248-
CCSpriteTexCoordSet texCoords = [CCSprite textureCoordsForTexture:self.texture withRect:rect rotated:rotated xFlipped:_flipX yFlipped:_flipY];
253+
CCSpriteTexCoordSet texCoords = [CCSprite textureCoordsForTexture:texture withRect:rect rotated:rotated xFlipped:_flipX yFlipped:_flipY];
249254
_verts.bl.texCoord1 = texCoords.bl;
250255
_verts.br.texCoord1 = texCoords.br;
251256
_verts.tr.texCoord1 = texCoords.tr;
@@ -533,7 +538,7 @@ -(void) setNormalMapSpriteFrame:(CCSpriteFrame*)frame
533538
// If there is no texture set on the sprite, set the sprite's texture rect from the
534539
// normal map's sprite frame. Note that setting the main texture, then the normal map,
535540
// and then removing the main texture will leave the texture rect from the main texture.
536-
[self setTextureRect:frame.rect rotated:frame.rotated untrimmedSize:frame.originalSize];
541+
[self setTextureRect:frame.rect forTexture:frame.texture rotated:frame.rotated untrimmedSize:frame.originalSize];
537542
}
538543

539544
// Set the second texture coordinate set from the normal map's sprite frame.

0 commit comments

Comments
 (0)