Walking by mouse click
We modify the World
class to listen on mouse click event. When the mouse clicks the world, we get the isometric tile position from the mouse screen coordinate. The map
is the reference to the IsometricMapData
class which contains the A* pathfinding class. We set up the starting and ending points for the pathfinding class to find a path solution. Then we pass the path to the WalkingAvatar
class to follow. At last we need to update the position in the room variables.
private function onMapClicked(e:MouseEvent):void { var newIsoPosition:Point = map.s2i(stage.mouseX,stage.mouseY); if (!map.isWalkable(newIsoPosition.x,newIsoPosition.y)){ trace("can't walk to there"); return; } /* find the path by A* pathfinding class */ map.astarMap.setEndPoints(myAvatar.isoPosition.x,_myAvatar. ...
Get Flash Multiplayer Virtual Worlds now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.