ios - My Sprite AI is working incorrectly. Why? -


i want 2 enemies set on attack mode, stands last enemy added being set on attack mode.

is there way around this? tips or suggestions appreciated. if need more code please let me know.

  -(void)viewdidload {   (_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];   (_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];   } 

look @ loop in viewdidload. first, use ivar loop variable. not want. second, assign self.enemy in each iteration, call enemyattack after loop has completed.

further, enemyattack not take parameters, uses internal state. since called after loop has iterated on objects, self.enemy last object in collection (if there in collection).

thus, not surprising see last item being activated enemy.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -