0

私はKobold2D+TexturePackerを使用しています(どちらも現時点で最後のバージョンです)。

spriteWithFile:メソッドを使用してCCSpriteオブジェクトを作成し、必要に応じて配置すると、問題なく表示されます。

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

spriteWithFile:

ただし、別の方法では、spriteWithSpriteFrameName:を使用してテクスチャをロードすると、オブジェクトが適切に配置されません。

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

spriteWithSpriteFrameName:

なんで?

4

1 に答える 1

0

代わりになどbackground.texture.contentSize.widthを使用してbackground.contentSize.widthください。

出典:iphone用のcocos2dでCCSpriteの幅と高さを取得する方法

于 2013-02-15T12:10:22.123 に答える