mapLayer.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { leftButtomStatPos, tableData, tiledSize } from "./DataConfig";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class MapLayer extends cc.Component {
  5. graphics: cc.Graphics
  6. start() {
  7. this.initMap()
  8. }
  9. public initMap() {
  10. this.graphics = this.node.getChildByName('floorLayer').getComponent(cc.Graphics)
  11. this.graphics.clear()
  12. //1.底板
  13. this.graphics.rect(leftButtomStatPos.x, leftButtomStatPos.y, tiledSize.width * tableData[0].length, tiledSize.height * tableData.length)
  14. this.graphics.fill()
  15. this.graphics.close()
  16. this.graphics.stroke()
  17. this.graphics.strokeColor = new cc.Color().fromHEX('#33A70A');
  18. // 2画地图表格
  19. for (let i = 1; i < tableData[0].length; i++) {
  20. for (let j = 1; j < tableData.length; j++) {
  21. let row1 = cc.v2(leftButtomStatPos.x + 0, j * tiledSize.height + leftButtomStatPos.y)
  22. let row2 = cc.v2(leftButtomStatPos.x + tableData[0].length * tiledSize.width, j * tiledSize.height + leftButtomStatPos.y)
  23. this.graphics.moveTo(row1.x, row1.y)
  24. this.graphics.lineTo(row2.x, row2.y)
  25. let line1 = cc.v2(leftButtomStatPos.x + i * tiledSize.width, leftButtomStatPos.y)
  26. let line2 = cc.v2(leftButtomStatPos.x + i * tiledSize.width, tableData.length * tiledSize.height + leftButtomStatPos.y)
  27. this.graphics.moveTo(line1.x, line1.y)
  28. this.graphics.lineTo(line2.x, line2.y)
  29. }
  30. }
  31. this.graphics.stroke()
  32. }
  33. // update (dt) {}
  34. }