Commit ed971814 authored by Seaborn Lee's avatar Seaborn Lee

refactor: extract BaseBgManager

parent 458d3c90
...@@ -7,4 +7,5 @@ ...@@ -7,4 +7,5 @@
/publish/publish/android /publish/publish/android
/publish/publish/ios /publish/publish/ios
/publish/publish/*.zip /publish/publish/*.zip
/node_modules /node_modulestags
\ No newline at end of file tags
{ {
"ver": "1.2.7", "ver": "1.2.9",
"uuid": "57ea7c61-9b8b-498a-b024-c98ee9124beb", "uuid": "57ea7c61-9b8b-498a-b024-c98ee9124beb",
"asyncLoadAssets": false, "asyncLoadAssets": false,
"autoReleaseAssets": true, "autoReleaseAssets": true,
......
This diff is collapsed.
cc.Class({
properties: {
_context: null,
},
setContext(ctx) {
this._context = ctx;
},
ctor() {},
toTop(item) {
item.y = this._context.bgHeight / 2;
item.anchorY = 1;
item.scale = this._context.bgWidth / item.width;
},
toBottom(item) {
item.y = -this._context.bgHeight / 2;
item.anchorY = 0;
item.scale = this._context.bgWidth / item.width;
},
toLeft(item) {
item.x = -this._context.bgWidth / 2;
item.anchorX = 0;
item.scale = this._context.bgHeight / item.height;
},
toRight(item) {
item.x = this._context.bgWidth / 2;
item.anchorX = 1;
item.scale = this._context.bgHeight / item.height;
},
});
{
"ver": "1.0.8",
"uuid": "0520cb4a-1cc8-4344-9355-72fa942c91b7",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
import {getSprNode} from "./util" import { getSprNode } from "./util";
cc.Class({ import BaseBgManager from "./BaseBgManager";
properties: {
bgArr: {
default: []
},
_bgWidth: 0,
_bgHeight: 0,
_mapScaleMin: 1,
_mapScaleMax: 1,
},
ctor(width, height, mapScaleMin, mapScaleMax) {
this._bgWidth = width;
this._bgHeight = height;
this._mapScaleMin = mapScaleMin;
this._mapScaleMax = mapScaleMax;
this.initAllBg();
},
initAllBg() { cc.Class({
extends: BaseBgManager,
for( let i=0; i<5; i++) { properties: {
const bg = this.initOneBg(i+1); bgArr: {
this.bgArr.push(bg); default: [],
}
}, },
},
initOneBg(id) { initAllBg() {
for (let i = 0; i < 5; i++) {
const bg = this.initOneBg(i + 1);
this.bgArr.push(bg);
}
},
const bg = getSprNode("bg/"+id+"/bg_"+id); initOneBg(id) {
bg.scale = this._mapScaleMax; const bg = getSprNode("bg/" + id + "/bg_" + id);
bg.scale = this._context.mapScaleMax;
const bgItemLayer = new cc.Node(); const bgItemLayer = new cc.Node();
bgItemLayer.scale = 1 / bg.scale; bgItemLayer.scale = 1 / bg.scale;
bg.addChild(bgItemLayer); bg.addChild(bgItemLayer);
const itemTop = getSprNode("bg/"+id+"/bg_top"+id)
bgItemLayer.addChild(itemTop, 1);
itemTop.y = this._bgHeight / 2;
itemTop.anchorY = 1;
itemTop.scale = this._bgWidth / itemTop.width;
const itemTop = getSprNode("bg/" + id + "/bg_top" + id);
const itemBottom = getSprNode("bg/"+id+"/bg_bottom"+id) bgItemLayer.addChild(itemTop, 1);
bgItemLayer.addChild(itemBottom, 1); this.toTop(itemTop);
itemBottom.y = -this._bgHeight / 2;
itemBottom.anchorY = 0;
itemBottom.scale = this._bgWidth / itemBottom.width;
const item = getSprNode("bg/"+id+"/bg_dian"+id) const itemBottom = getSprNode("bg/" + id + "/bg_bottom" + id);
bgItemLayer.addChild(item); bgItemLayer.addChild(itemBottom, 1);
item.x = -this._bgWidth / 10 * 4; this.toBottom(itemBottom);
item.y = -this._bgHeight / 6;
item.scale = this._mapScaleMin;
if (id == 4) { const item = getSprNode("bg/" + id + "/bg_dian" + id);
bgItemLayer.addChild(item);
item.x = (-this._context.bgWidth / 10) * 4;
item.y = -this._context.bgHeight / 6;
item.scale = this._context.mapScaleMin;
itemTop.scale = this._mapScaleMin; if (id == 4) {
itemTop.scale = this._context.mapScaleMin;
const itemLeft = getSprNode("bg/"+id+"/bg_left") const itemLeft = getSprNode("bg/" + id + "/bg_left");
bgItemLayer.addChild(itemLeft); bgItemLayer.addChild(itemLeft);
itemLeft.x = -this._bgWidth / 2; this.toLeft(itemLeft);
itemLeft.anchorX = 0;
itemLeft.scale = this._bgHeight / itemLeft.height;
const itemRight = getSprNode("bg/"+id+"/bg_right") const itemRight = getSprNode("bg/" + id + "/bg_right");
bgItemLayer.addChild(itemRight); bgItemLayer.addChild(itemRight);
itemRight.x = this._bgWidth / 2; this.toRight(itemRight);
itemRight.anchorX = 1; }
itemRight.scale = this._bgHeight / itemRight.height;
}
return bg; return bg;
}, },
getNext () { getNext() {
return this.bgArr[3]; if (this.bgArr.length === 0) {
this.initAllBg();
} }
}) return this.bgArr[3];
\ No newline at end of file },
});
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
"packages": "packages", "packages": "packages",
"name": "play", "name": "play",
"id": "9af72fd2-44a6-4131-8ea3-3e1b3fa22231", "id": "9af72fd2-44a6-4131-8ea3-3e1b3fa22231",
"version": "2.4.0", "version": "2.4.4",
"isNew": false "isNew": false
} }
\ No newline at end of file
{ {
"last-module-event-record-time": 1600677246969 "last-module-event-record-time": 1600677246969,
"migrate-history": [
"cloud-function"
]
} }
{ {
"game": { "game": {
"name": "未知游戏", "name": "UNKNOW GAME",
"appid": "UNKNOW" "appid": "UNKNOW"
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment