public void MoveEntity(Map.Map.Position destination, Action <bool> completionHandler) { var centity = (Entity)Entity; var comp = (CharacterSpriteComponent)Entity.GetComponent(typeof(CharacterSpriteComponent)); if (comp == null) { return; } GKGraphNode[] path = GameViewController.CurrentScene.CurrentMap.FindPath(centity.Model.StartPosition, destination, false); if (teleportation) { if (path == null) { completionHandler(false); return; } var lastNode = (MapGraphNode)path.Last(); CoreGraphics.CGPoint point = GameViewController.CurrentScene.CurrentMap.PositionToPoint(lastNode.NodePosition, true); comp.Sprite.Position = point; centity.Model.StartPosition = lastNode.NodePosition; comp.Sprite.ZPosition = GameViewController.CurrentScene.CurrentMap.ZLevelForPosition(lastNode.NodePosition); completionHandler(true); } else { FollowPath(path, completionHandler); } }
void UpdateMapViews() { if (map == null) { return; } for (int row = 0; row < map.Height; row++) { for (int column = 0; column < map.Width; column++) { Map.Map.Position position = new Map.Map.Position { Row = row, Column = column }; CGPoint point = map.PositionToPoint (position); Tile t = map.TileAtPosition (position); var bbox = map.BoundingBoxForTileAtPosition (position); Console.WriteLine ("{0}", point); Console.WriteLine ("bbox: {0}", bbox); NSImageView tileView = new NSImageView (bbox) {Image = t.Image, TranslatesAutoresizingMaskIntoConstraints = false}; AddSubview (tileView, NSWindowOrderingMode.Below, overlay); var constraint = NSLayoutConstraint.Create (this, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, tileView, NSLayoutAttribute.CenterX, 1, -point.X); AddConstraint (constraint); constraint = NSLayoutConstraint.Create (this, NSLayoutAttribute.Top, NSLayoutRelation.Equal, tileView, NSLayoutAttribute.Bottom, 1, -65 + point.Y); AddConstraint (constraint); constraint = NSLayoutConstraint.Create (tileView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, bbox.Width); tileView.AddConstraint (constraint); constraint = NSLayoutConstraint.Create (tileView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, bbox.Height); tileView.AddConstraint (constraint); } } }