Posted By

solgems on 01/10/11


Tagged

Sprites cocos2d


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tintenklecks


initialising and populating an array of Sprites


 / Published in: Objective C
 

  1. for (int i = 0; i < 9; i++ ) {
  2. //create a slot object with a label
  3. //add the object to the slots array
  4.  
  5. //sprite
  6. [slots addObject: [[[Slot alloc] initWithSprite:[CCSprite spriteWithFile:@"hole.png"]
  7. withPos_x:count%3*cellWidth+offset_x
  8. withPos_y:count/3*cellHeight+offset_y
  9. isOccupied:NO] autorelease]];
  10.  
  11. //add the sprite to the layer
  12. [self addChild: ((Slot*) [slots objectAtIndex:i]).sprite];
  13.  
  14. count++;
  15. }

Report this snippet  

You need to login to post a comment.