SquareGrid.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. mapNode: {
  5. default: null,
  6. type: cc.TiledMap,
  7. },
  8. },
  9. // LIFE-CYCLE CALLBACKS:
  10. // onLoad () {},
  11. start() {
  12. this.node.zIndex = -1000;
  13. cc.log('测试地图:', this.mapNode.getMapSize());
  14. },
  15. // update (dt) {},
  16. });
  17. // Square grid for A* Demonstration
  18. // Copyright 2007 Amit J Patel, amitp@cs.stanford.edu
  19. // License: MIT (see LICENSE file)
  20. // package {
  21. // import Graph;
  22. // import flash.geom.Point;
  23. // public class SquareGrid extends Graph {
  24. // public var size:int; // side of a square, in pixels
  25. // public var width:int; // number of squares across
  26. // public var height:int; // number of squares high
  27. // public function SquareGrid(width_:int, height_:int, size_:int) {
  28. // width = width_;
  29. // height = height_;
  30. // size = size_;
  31. // }
  32. // override public function allNodes():Array {
  33. // var result:Array = new Array();
  34. // for (var u:int = 0; u != width; u++) {
  35. // for (var v:int = 0; v != height; v++) {
  36. // result.push({ u: u, v: v });
  37. // }
  38. // }
  39. // return result;
  40. // }
  41. // override public function centerNode():Object {
  42. // return { u: Math.floor(width/2), v: Math.floor(height/2) };
  43. // }
  44. // override public function nodeToString(n:Object):String {
  45. // return ""+n.u+","+n.v;
  46. // }
  47. // override public function stringToNode(s:String):Object {
  48. // var fields:Array = s.split(",", 2);
  49. // return {u: Number(fields[0]), v: Number(fields[1])};
  50. // }
  51. // override public function nodesEqual(n1:Object, n2:Object):Boolean {
  52. // return (n1.u == n2.u) && (n1.v == n2.v);
  53. // }
  54. // override public function nodeVertices(n:Object):Array {
  55. // return new Array({ u: n.u, v: n.v },
  56. // { u: n.u+1, v: n.v },
  57. // { u: n.u+1, v: n.v+1 },
  58. // { u: n.u, v: n.v+1 });
  59. // }
  60. // override public function vertexGeom(v:Object):Point {
  61. // return new Point(v.u * size, v.v * size);
  62. // }
  63. // override public function nodeValid(n:Object):Boolean {
  64. // return (0 <= n.u && n.u < width && 0 <= n.v && n.v < height);
  65. // }
  66. // override public function pointToNode(p:Point):Object {
  67. // // optimization of what the base class would do
  68. // var u:Number = p.x / size;
  69. // var v:Number = p.y / size;
  70. // if (nodeValid({u: u, v: v})) {
  71. // return { u: Math.floor(u), v: Math.floor(v) };
  72. // } else {
  73. // return null;
  74. // }
  75. // }
  76. // override public function nodeNeighbors(n:Object):Array {
  77. // var r:Array = new Array({ u: n.u + 1, v: n.v },
  78. // { u: n.u, v: n.v + 1 },
  79. // { u: n.u - 1, v: n.v },
  80. // { u: n.u, v: n.v - 1 });
  81. // var result:Array = new Array();
  82. // for (var i:int = 0; i != r.length; i++) {
  83. // if (nodeValid(r[i])) {
  84. // result.push(r[i]);
  85. // }
  86. // }
  87. // return result;
  88. // }
  89. // override public function distance(a:Object, b:Object):Number {
  90. // return Math.abs(a.u - b.u) + Math.abs(a.v - b.v);
  91. // }
  92. // }
  93. // }