1
我有下面的代碼在遊戲層多雪碧表時:錯誤使用與cocos2d的
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"cow_sprite.plist"];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"ray_sprite.plist"];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"chicken_sprite.plist"];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"tank_sprite.plist"];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"human_sprite.plist"];
self.raySpriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"ray_sprite.png"];
self.tankSpriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"tank_sprite.png"];
self.chickenSpriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"chicken_sprite.png"];
self.cowSpriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"cow_sprite.png"];
self.humanSpriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"human_sprite.png"];
[self addChild:self.raySpriteSheet];
[self addChild:self.tankSpriteSheet];
[self addChild:self.chickenSpriteSheet];
[self addChild:self.cowSpriteSheet];
[self addChild:self.humanSpriteSheet];
for (int i = 0; i < 13; ++i) {
Dice* d = [[Dice alloc] initRandom];
if (d.fileNum == 0 || d.fileNum == 1) {
[self.raySpriteSheet addChild:d.sprite];
}else if(d.fileNum == 2){
[self.tankSpriteSheet addChild:d.sprite];
}else if(d.fileNum == 3){
[self.chickenSpriteSheet addChild:d.sprite];
}else if(d.fileNum == 4){
[self.cowSpriteSheet addChild:d.sprite];
}else if(d.fileNum == 5){
[self.humanSpriteSheet addChild:d.sprite];
}
[rollDiceArray addObject:d];
}
的想法是,我希望能夠用5和不同的精靈表5個獨立骰子動畫。我爲每個die預先確定一個值,然後分配一個精靈/動畫,最後將該精靈添加到相應的CCSpriteBatchNode。
這將使它通過第一次迭代但隨後在第二的錯誤,給這個錯誤:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite is not using the same texture id'
有什麼想法?
這聽起來像它應該修復它。我將要度過我的下午,把一切都變成一個大精靈。應該能夠把它放在一個整體。唯一需要弄清楚的是如何在一張紙上區分不同的精靈(坦克/雷/牛/雞/人)。 – rnystrom
你有他們的名字。當然,你會想使用紋理貼圖程序,如TexturePacker:http://www.texturepacker.com – LearnCocos2D
你釘了它。不過,我還有一些其他問題沒有顯示出來。沒有錯誤或任何事情。我爲此創造了另一個問題。如果您有任何想法,請嘗試一下。 http://stackoverflow.com/questions/8159649/spritesheet-with-cocos2d-not-displaying-anything – rnystrom