Commit ed971814 authored by Seaborn Lee's avatar Seaborn Lee

refactor: extract BaseBgManager

parent 458d3c90
......@@ -7,4 +7,5 @@
/publish/publish/android
/publish/publish/ios
/publish/publish/*.zip
/node_modules
\ No newline at end of file
/node_modulestags
tags
{
"ver": "1.2.7",
"ver": "1.2.9",
"uuid": "57ea7c61-9b8b-498a-b024-c98ee9124beb",
"asyncLoadAssets": false,
"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"
cc.Class({
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();
},
import { getSprNode } from "./util";
import BaseBgManager from "./BaseBgManager";
initAllBg() {
for( let i=0; i<5; i++) {
const bg = this.initOneBg(i+1);
this.bgArr.push(bg);
}
cc.Class({
extends: BaseBgManager,
properties: {
bgArr: {
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);
bg.scale = this._mapScaleMax;
initOneBg(id) {
const bg = getSprNode("bg/" + id + "/bg_" + id);
bg.scale = this._context.mapScaleMax;
const bgItemLayer = new cc.Node();
bgItemLayer.scale = 1 / bg.scale;
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 bgItemLayer = new cc.Node();
bgItemLayer.scale = 1 / bg.scale;
bg.addChild(bgItemLayer);
const itemBottom = getSprNode("bg/"+id+"/bg_bottom"+id)
bgItemLayer.addChild(itemBottom, 1);
itemBottom.y = -this._bgHeight / 2;
itemBottom.anchorY = 0;
itemBottom.scale = this._bgWidth / itemBottom.width;
const itemTop = getSprNode("bg/" + id + "/bg_top" + id);
bgItemLayer.addChild(itemTop, 1);
this.toTop(itemTop);
const item = getSprNode("bg/"+id+"/bg_dian"+id)
bgItemLayer.addChild(item);
item.x = -this._bgWidth / 10 * 4;
item.y = -this._bgHeight / 6;
item.scale = this._mapScaleMin;
const itemBottom = getSprNode("bg/" + id + "/bg_bottom" + id);
bgItemLayer.addChild(itemBottom, 1);
this.toBottom(itemBottom);
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")
bgItemLayer.addChild(itemLeft);
itemLeft.x = -this._bgWidth / 2;
itemLeft.anchorX = 0;
itemLeft.scale = this._bgHeight / itemLeft.height;
const itemLeft = getSprNode("bg/" + id + "/bg_left");
bgItemLayer.addChild(itemLeft);
this.toLeft(itemLeft);
const itemRight = getSprNode("bg/"+id+"/bg_right")
bgItemLayer.addChild(itemRight);
itemRight.x = this._bgWidth / 2;
itemRight.anchorX = 1;
itemRight.scale = this._bgHeight / itemRight.height;
}
const itemRight = getSprNode("bg/" + id + "/bg_right");
bgItemLayer.addChild(itemRight);
this.toRight(itemRight);
}
return bg;
},
return bg;
},
getNext () {
return this.bgArr[3];
getNext() {
if (this.bgArr.length === 0) {
this.initAllBg();
}
})
\ No newline at end of file
return this.bgArr[3];
},
});
......@@ -3,6 +3,6 @@
"packages": "packages",
"name": "play",
"id": "9af72fd2-44a6-4131-8ea3-3e1b3fa22231",
"version": "2.4.0",
"version": "2.4.4",
"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": {
"name": "未知游戏",
"name": "UNKNOW GAME",
"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