first
This commit is contained in:
39
assets/script/game/map/view/map/layer/EntityLayer.ts
Normal file
39
assets/script/game/map/view/map/layer/EntityLayer.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2022-08-04 15:22:33
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2023-05-12 18:04:45
|
||||
*/
|
||||
import { Component, Node, _decorator } from 'cc';
|
||||
import { Timer } from '../../../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer';
|
||||
import Charactor from '../charactor/Charactor';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* 物体层
|
||||
* 注:
|
||||
* 1、这里的深度排序,如果有性能问题,可考虑修改为非每帧排序
|
||||
* 2、如果全3D世界显示角色相关显示对象,则不需要2D深度排序,只引用2D地图上的位置信息
|
||||
*/
|
||||
@ccclass('EntityLayer')
|
||||
export default class EntityLayer extends Component {
|
||||
private timer: Timer = new Timer(0.2);
|
||||
|
||||
update(dt: number) {
|
||||
if (this.timer.update(dt))
|
||||
this.node.children.sort(this.zIndexSort);
|
||||
}
|
||||
|
||||
private zIndexSort(a: Node, b: Node) {
|
||||
let a_zIndex = a.getComponent(Charactor)!.zIndex;
|
||||
let b_zIndex = b.getComponent(Charactor)!.zIndex;
|
||||
return a_zIndex - b_zIndex;
|
||||
}
|
||||
|
||||
public clear() {
|
||||
this.node.children.forEach(n => {
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
11
assets/script/game/map/view/map/layer/EntityLayer.ts.meta
Normal file
11
assets/script/game/map/view/map/layer/EntityLayer.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6639aca8-e031-4a65-8094-d8e059cf26fe",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
134
assets/script/game/map/view/map/layer/MapLayer.ts
Normal file
134
assets/script/game/map/view/map/layer/MapLayer.ts
Normal file
@@ -0,0 +1,134 @@
|
||||
import { Component, Layers, Node, Sprite, SpriteFrame, Texture2D, UITransform, Vec3, _decorator } from 'cc';
|
||||
import { oops } from '../../../../../../../extensions/oops-plugin-framework/assets/core/Oops';
|
||||
import { LayerUtil } from '../../../../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil';
|
||||
import { smc } from '../../../../common/SingletonModuleComp';
|
||||
import { MapLoadModel } from '../base/MapLoadModel';
|
||||
import MapParams from '../base/MapParams';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* 地图层
|
||||
* @author 落日故人 QQ 583051842
|
||||
*
|
||||
*/
|
||||
@ccclass('MapLayer')
|
||||
export default class MapLayer extends Component {
|
||||
/** 切割小图片集 */
|
||||
private _sliceImgDic: { [key: string]: Sprite | null } = {};
|
||||
private _mapParams: MapParams | null = null;
|
||||
|
||||
@property(Sprite)
|
||||
private bgImg: Sprite | null = null;
|
||||
|
||||
public init(mapParams: MapParams): void {
|
||||
this._mapParams = mapParams;
|
||||
|
||||
if (!this.bgImg) {
|
||||
var bgNode: Node = new Node();
|
||||
this.node.addChild(bgNode);
|
||||
bgNode.layer = Layers.Enum.UI_2D;
|
||||
|
||||
this.bgImg = bgNode.addComponent(Sprite);
|
||||
this.bgImg.sizeMode = Sprite.SizeMode.RAW;
|
||||
bgNode.getComponent(UITransform)!.anchorX = 0;
|
||||
bgNode.getComponent(UITransform)!.anchorY = 0;
|
||||
}
|
||||
|
||||
var spriteFrame: SpriteFrame = new SpriteFrame();
|
||||
spriteFrame.texture = this._mapParams.bgTex!;
|
||||
|
||||
this.bgImg.spriteFrame = spriteFrame;
|
||||
|
||||
//如果是马赛克小地图,则需要把小地图缩放成原始地图一样大小
|
||||
if (mapParams.mapLoadModel == MapLoadModel.slices) {
|
||||
this.bgImg.getComponent(UITransform)!.width = mapParams.mapWidth;
|
||||
this.bgImg.getComponent(UITransform)!.height = mapParams.mapHeight;
|
||||
}
|
||||
|
||||
this.getComponent(UITransform)!.width = this.width;
|
||||
this.getComponent(UITransform)!.height = this.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据视图区域加载小地图
|
||||
* @param px 滚动视图左上角的x坐标
|
||||
* @param py 滚动视图左上角的y坐标
|
||||
*
|
||||
*/
|
||||
public loadSliceImage(px: number, py: number): void {
|
||||
// var iy1: number = Math.floor(py / this._mapParams!.sliceHeight);
|
||||
// var iy2: number = Math.floor((py + this._mapParams!.viewHeight) / this._mapParams!.sliceHeight);
|
||||
|
||||
// var jx1: number = Math.floor(px / this._mapParams!.sliceWidth);
|
||||
// var jx2: number = Math.floor((px + this._mapParams!.viewWidth) / this._mapParams!.sliceWidth);
|
||||
|
||||
// var key: string;
|
||||
|
||||
// for (var i: number = iy1; i <= iy2; i++) {
|
||||
// for (var j: number = jx1; j <= jx2; j++) {
|
||||
// key = (i + 1) + "_" + (j + 1); // 图片的索引是从1开始的,所以要加1
|
||||
|
||||
// if (!this._sliceImgDic[key]) {
|
||||
// let bitmap: Sprite = this.getSliceSprite(key)
|
||||
// this._sliceImgDic[key] = bitmap;
|
||||
// this.node.addChild(bitmap.node);
|
||||
// bitmap.node.position = new Vec3(j * this._mapParams!.sliceWidth, i * this._mapParams!.sliceHeight, 0)
|
||||
|
||||
// // var path: string = `maps/${this._mapParams!.bgName}/${this._mapParams!.bgName}/slices/${key}/texture`;
|
||||
// // oops.res.load("remote", path, Texture2D, (error: Error | null, tex: Texture2D) => {
|
||||
// var path: string = smc.map.MapModel.getResContentSlices(this._mapParams!.bgName, key);
|
||||
// oops.res.load(path, Texture2D, (error: Error | null, tex: Texture2D) => {
|
||||
// if (error) {
|
||||
// console.error(error);
|
||||
// }
|
||||
// var spriteFrame: SpriteFrame = new SpriteFrame();
|
||||
// spriteFrame.texture = tex;
|
||||
// bitmap.spriteFrame = spriteFrame;
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private getSliceSprite(name: string) {
|
||||
var node: Node = new Node(name);
|
||||
node.layer = LayerUtil.MAP.mask; // Layers.Enum.UI_2D;
|
||||
var sprite: Sprite = node.addComponent(Sprite);
|
||||
sprite.sizeMode = Sprite.SizeMode.RAW;
|
||||
node.getComponent(UITransform)!.anchorX = 0;
|
||||
node.getComponent(UITransform)!.anchorY = 0;
|
||||
return sprite;
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this.bgImg!.spriteFrame = null;
|
||||
|
||||
for (var key in this._sliceImgDic) {
|
||||
var sprite: Sprite | null = this._sliceImgDic[key];
|
||||
sprite && sprite.node.destroy();
|
||||
this._sliceImgDic[key] = null;
|
||||
delete this._sliceImgDic[key];
|
||||
}
|
||||
}
|
||||
|
||||
public get bgImage(): Sprite {
|
||||
return this.bgImg!;
|
||||
}
|
||||
|
||||
public get width(): number {
|
||||
if (this.bgImg) {
|
||||
return this.bgImg.getComponent(UITransform)!.width;
|
||||
}
|
||||
|
||||
return this._mapParams!.viewWidth;
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
if (this.bgImg) {
|
||||
return this.bgImg.getComponent(UITransform)!.height;
|
||||
}
|
||||
|
||||
return this._mapParams!.viewHeight;
|
||||
}
|
||||
}
|
||||
11
assets/script/game/map/view/map/layer/MapLayer.ts.meta
Normal file
11
assets/script/game/map/view/map/layer/MapLayer.ts.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "753fb70a-638e-44d4-b736-f8696df44858",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user