Problem with migrating from Texture2D to CCTexture2D (Setting CCSprite texture)

Posted by marie on Stack Overflow See other posts from Stack Overflow or by marie
Published on 2010-04-27T10:14:03Z Indexed on 2010/04/28 3:13 UTC
Read the original article Hit count: 425

Filed under:
|

My problem is that whenever I change the texture of a sprite, the new texture will retain the size of the original sprite's texture.

I have this code:

mySprite = [CCSprite spriteWithFile:@"mySprite.png"]];

...

// change current stage here

CCTexture2D *newTexture=[[[CCTexture2D alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"stage number %d.png",currentStageNumber]]]autorelease];

[mySprite setTexture:newTexture];

The new sprite is stretched or compressed depending on the size of the original sprite. If the original sprite is larger, the new texture is stretched.

I didn't have this problem when I was using cocos2d v0.8

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about cocos2d-iphone

Related posts about cocos2d