Instead background.texture.contentSize.width
use background.contentSize.width
et cetera.
Source: how to obtain a CCSprite's width and height in cocos2d for iphone
Pergunta
I use Kobold2D + TexturePacker (both are the last version at this moment).
When I create an CCSprite object using the spriteWithFile: method, and place as it should, it looks fine.
CGSize screenSize = [CCDirector sharedDirector].winSize;
background = [CCSprite spriteWithFile:@"dir_bg.png"];
background.position = CGPointMake(screenSize.width - background.texture.contentSize.width / 2 - 10, background.texture.contentSize.height / 2 + 10);
[self addChild:background];
controller = [CCSprite spriteWithFile:@"dir_big.png"];
controller.position = background.position;
[self addChild:controller];
But with a different method, with the loading of textures using spriteWithSpriteFrameName:, the object is not placed as it should.
[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Textures.plist"];
CGSize screenSize = [CCDirector sharedDirector].winSize;
background = [CCSprite spriteWithSpriteFrameName:@"dir_bg.png"];
background.position = CGPointMake(screenSize.width - background.texture.contentSize.width / 2 - 10, background.texture.contentSize.height / 2 + 10);
[self addChild:background];
controller = [CCSprite spriteWithSpriteFrameName:@"dir_big.png"];
controller.position = background.position;
[self addChild:controller];
Why?
Solução
Instead background.texture.contentSize.width
use background.contentSize.width
et cetera.
Source: how to obtain a CCSprite's width and height in cocos2d for iphone