0

I want my two enemies to be set on attack mode, however as it stands only the last enemy added is being set on attack mode.

Is there any way around this? Any tips or suggestions is appreciated. If you need more code please let me know.

  -(void)ViewDidLoad {
  for (_enemyPoint in [self.enemyGroup objects]) {
  self.enemy = [[CCSprite alloc] initWithFile:@"Icon.png"];
  self.enemy.scale = 32.0f/57.0f;
  self.enemy.position = CGPointMake([_enemyPoint[@"x"] integerValue],    [_enemyPoint[@"y"] integerValue]);
  [self addChild:self.enemy];
    }
  self.pathfinder = [HUMAStarPathfinder pathfinderWithTileMapSize:self.tileMap.mapSize
                                                         tileSize:self.tileMap.tileSize
                                                           delegate:self];
    [self enemyAttack];

                    }


  - (void)enemyAttack{

self.epath = [self.pathfinder findPathFromStart:self.enemy.position
                                          toTarget:self.player.position];
self.eactions = [NSMutableArray array];


for (_epointValueInPath in self.epath) {
   self.epoint = _epointValueInPath.CGPointValue;

   self.emoveTo = [CCMoveTo actionWithDuration:1.0f position:self.epoint];
    [self.eactions addObject:self.emoveTo];

}

self.esequence = [CCSequence actionWithArray:self.eactions];
[self.enemy runAction:self.esequence];
  }
neowinston
  • 7,584
  • 10
  • 52
  • 83

2 Answers2

0

Look at your loop in viewDidLoad. First, you use an iVar as the loop variable. Probably not what you want. Second, you assign self.enemy in each iteration, but you call enemyAttack after the loop has completed.

Further, enemyAttack does not take any parameters, so it uses internal state. Since it is called after the loop has iterated over all objects, self.enemy will always be the last object in the collection (if there is anything in the collection).

Thus, it is not surprising that you only see the last item being activated as an enemy.

Jody Hagins
  • 27,943
  • 6
  • 58
  • 87
0

Have you tried to put the [self enemyAttack]; invocation inside the for loop?

neowinston
  • 7,584
  • 10
  • 52
  • 83