New PathFinding

  ... information about changes and new features of AndEngine,

Re: New PathFinding

Postby Rev.Tyler » Sat May 21, 2011 9:49 pm

You can use an entity modifier called PathModifier to move AnimatedSprites.

The path returned from the a* isn't the same path for the PathModifier but it's easy to convert with the following loop:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Path walkPath = new AStarPathFinder<UnitSprite>(GameBoard.Instance, 3, false).findPath(this, 1000, this.column, this.row, column, row);
  2. PathModifier.Path path = new PathModifier.Path(walkPath.getLength());
  3. for(int i = 0; i < walkPath.getLength(); i ++){
  4.         Step step = walkPath.getStep(i);
  5.         float stepX = GameBoard.Instance.boardTiles[step.getTileColumn()][step.getTileRow()].getX();
  6.         float stepY = GameBoard.Instance.boardTiles[step.getTileColumn()][step.getTileRow()].getY() - 30;
  7.         path = path.to(stepX, stepY);
  8. }
  9.  
  10. this.addShapeModifier(new PathModifier(2, path));
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


GameBoard.Instance.boardTiles[][] is my array of tiles that I made with some sprites.
Rev.Tyler
 
Posts: 161
Joined: Tue Dec 28, 2010 5:02 am

Previous

Return to Updates

Who is online

Users browsing this forum: No registered users and 1 guest