作为测试我已经为批处理节点添加了一些精灵。它们都以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];
答案 0 :(得分:0)
我以前从未见过[batch appendChild:]。在cocos2d类引用上我找不到它。你试过[批处理addChild:child]; ?添加相同的CCSprite可能会出现多次问题,请尝试为每个图像创建一个新的sprite并添加它。
例如:
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];