我不了解循环中的Cocos 2D精灵创建行为

时间:2014-03-15 10:19:24

标签: ios cocos2d-iphone

使用此代码怪物不会出现,只有英雄节目

for (int j = 0; j <= _discrH; j++)
   {
   for (int i = 0; i <= _discrW; i++)
        {
        CCSprite * sprite = [CCSprite spriteWithImageNamed:@"monster.png"] ;
        sprite.position  = ccp([self getCanvasXFromGameI : i],[self getCanvasYFromGameJ : j]);
        [_sprites addObject:sprite ];
         [self addChild:sprite];
        }
   } 
   _hero = [CCSprite spriteWithImageNamed:@"case1.png"];
   _hero.position  = ccp(0,0);
   [self addChild:_hero];

但是使用这个(无意义的)代码,怪物和英雄显示,我不明白为什么......

for (int j = 0; j <= _discrH; j++)
   {
   for (int i = 0; i <= _discrW; i++)
        {
        CCSprite * sprite = [CCSprite spriteWithImageNamed:@"monster.png"] ;
        sprite.position  = ccp([self getCanvasXFromGameI : i],[self getCanvasYFromGameJ : j]);
        [_sprites addObject:sprite ];
         [self addChild:sprite];
        }
   _hero = [CCSprite spriteWithImageNamed:@"case1.png"];
   _hero.position  = ccp(0,0);
   [self addChild:_hero];
   } 

任何想法我做错了什么?

0 个答案:

没有答案