initialising and populating an array of Sprites


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.