12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import { _decorator, Size, TiledMap, TiledObjectGroup, Vec3 } from 'cc';
- import { ModulerBase } from './ModulerBase';
- import { ObstacleMgr } from './ObstacleMgr';
- const { ccclass, property } = _decorator;
- @ccclass('MapMgr')
- export class MapMgr extends ModulerBase {
- private _tiledMap:TiledMap = null;
- private _tiledSize: Size = null;
- private _pathPoints: Vec3[] = [];
- tiledObjectGroup: TiledObjectGroup = null;
- protected onLoad(): void {
- this._tiledMap = this.getComponent(TiledMap);
- this._tiledSize = this._tiledMap.getTileSize();
- // this.tiledObjectGroup = this.getComponentInChildren(TiledObjectGroup);
- // this.tiledObjectGroup.getObjects();
- }
- start() {
-
- this._parseMap();
- }
- test(){
-
- }
- update(deltaTime: number) {
-
- }
- private _parseMap(){
- //获取瓦片地图的对象
- const objects = this._tiledMap.getObjectGroup("PATH").getObjects();
- //遍历所有对象 解析地图中的信息
- for (const obj of objects) {
- if(obj.name.includes("PT")){
- //截取字符串的第二个(0,1,2,3)=>字符"PT"后面的第一个
- const i = obj.name.slice(2);
- this._pathPoints[Number(i) - 1] = new Vec3(
- obj.x + this._tiledSize.width/2,
- obj.y - this._tiledSize.height/2)
- }
- else if(obj.name.includes("Obj")){
- //空地
- }
- else if(obj.name.includes("Ob")){
- //障碍物
- this.getModuler(ObstacleMgr).creatorObs(this.getCenterByObj(obj),0)
- }
- else if(obj.name.includes("T")){
- //赠送的炮台
- }
- }
- }
-
- getCenterByObj(obj): Vec3{
- return new Vec3(obj.x + obj.width / 2,
- obj.y - obj.height / 2
- )
- }
- getPath(): Vec3[]{
- return this._pathPoints;
- }
- // getPath(): Vec3[]{
- // const objects = this._tiledMap.getObjectGroup("PATH").getObjects();
- // const points: Vec3[] = [];
- // for (const obj of objects) {
- // if(obj.name.startsWith("PT")){
- // //截取字符串的第二个(0,1,2,3)=>字符"PT"后面的第一个
- // const i = obj.name.slice(2);
- // points[Number(i) - 1] = new Vec3(
- // obj.x + this._tiledSize.width/2,
- // obj.y - this._tiledSize.height/2)
- // }
- // }
- // return points;
- // }
- }
|