0

テストとして、バッチノードにいくつかのスプライトを追加しました。それらはすべて0,0で描画され、スプライトの位置を無視しているように見えます。これは、バッチノードに対して相対的であると私は考えました。私は何が欠けていますか?

CCLayer* splash = [[CCLayerColor alloc]initWithColor:ccc4(255,255,255,255)];
[self addChild:splash];

CCSpriteFrame* cf = [[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:@"circle.png"];

CCSpriteBatchNode* batch = [CCSpriteBatchNode batchNodeWithTexture:cf.texture];

CCSprite* test = [CCSprite  spriteWithSpriteFrameName:@"circle.png"];
test.position = CGPointMake(20,20);
test.color = ccc3(255,255,0);
[batch appendChild:test];
test = [CCSprite  spriteWithSpriteFrameName:@"square.png"];
test.position = CGPointMake(60,60);
test.color = ccc3(255,0,0);
[batch appendChild:test];
test = [CCSprite  spriteWithSpriteFrameName:@"square.png"];
test.position = CGPointMake(100,60);
test.color = ccc3(255,125,125);
[batch appendChild:test];
test = [CCSprite  spriteWithSpriteFrameName:@"bomb.png"];
test.position = CGPointMake(100,100);
test.color = ccc3(255,0,255);
[batch appendChild:test];
[splash addChild:batch];
4

1 に答える 1

0

[batch appendChild:]が使用されているのを見たことがありません。cocos2dクラスリファレンスで私はそれを見つけることができませんでした。[batch addChild:child]を試しましたか。?同じCCSpriteを数回追加することにも問題がある可能性があります。画像ごとに新しいスプライトを作成し、追加してみてください。

例えば:

    CCSprite* test = [CCSprite  spriteWithSpriteFrameName:@"circle.png"];
    test.position = CGPointMake(20,20);
    test.color = ccc3(255,255,0);
    [batch addChild:test];
    CCSprite* second = [CCSprite  spriteWithSpriteFrameName:@"square.png"];
    second.position = CGPointMake(60,60);
    second.color = ccc3(255,0,0);
    [batch addChild:second];
于 2012-12-27T00:08:59.023 に答える