iphone ios ipad cocos2d-iphone ccsprite

iphone - Spritesheet con Cocos2d sin mostrar nada



ios ipad (0)

Intento escribir una aplicación de demostración para aprender a usar mejor las hojas de sprites en Cocos2d. Hasta ahora, he conseguido que los sprites estén listos para funcionar, la hoja se ve muy bien, el código se ve bien ... ¡pero los sprites no se muestran!

Tengo objetos Dice que contienen el sprite y algunas funciones para seleccionar una cara aleatoria antes de animar el dado en la pantalla. Se supone que es como si estuvieras rodando.

El orden de operación que he usado es:

  • Agregue la plist de datos de sprites a la memoria caché de cuadros
  • Crear el nodo de lote de hoja de sprite
  • Inicialice los objetos de dados, eligiendo una cara aleatoria y agréguelos a la hoja de sprites (nodo de proceso por lotes)
  • Agregue la hoja de sprites (nodo de proceso por lotes) a la capa del juego

Aquí hay un enlace a todo el proyecto. Siéntase libre de apuñalarlo.

https://github.com/rnystrom/MartionDemo

Aquí hay fragmentos de lo que describí arriba y de lo que hace el objeto Dice:

// Add spritesheet to the sprite cache [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"spritesheet.plist"]; self.spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"spritesheet.png"]; for (int i = 0; i < kNumDice; ++i) { // Create Dice object // CODE BELOW HAPPENS HERE AT initRandom Dice* d = [[Dice alloc] initRandom]; // Add die to spritesheet [self.spriteSheet addChild:d.sprite]; // Add Dice object to the array of rollable dice [rollDiceArray addObject:d]; } // Add spritesheet to the game layer [self addChild:self.spriteSheet];

Aquí hay un resumen de lo que sucede en la inicialización de los dados (ver initRandom arriba):

// ... Sets up stuff like the # of frames, picking a random side of the die, etc ... // Add each frame to the frames array for(int i = 1; i <= numberFrames; i++) { if (i < 10) { [frames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%@0%d.png", self.face, i]]]; }else{ [frames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%@%d.png", self.face, i]]]; } } // Animation object with 0.04 seconds between each frame (~30fps) CCAnimation *anim = [CCAnimation animationWithFrames:frames delay:0.04f]; // Update the sprite with the new frames self.sprite = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"%@01.png", self.face]]; // Animate the sprite [self.sprite runAction:[CCAnimate actionWithAnimation:anim restoreOriginalFrame:NO]];