6a05cce4-3331-45d8-9bd4-8ac8bc7355e9.js
6.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
"use strict";
cc._RF.push(module, '6a05czkMzFF2JvUisi8c1Xp', 'ObjBaseView');
// scripts/prefabs/ObjBaseView.ts
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var Global_1 = require("../Global");
var TableDefine_1 = require("../kernel/table/TableDefine");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var ObjBaseView = /** @class */ (function (_super) {
__extends(ObjBaseView, _super);
function ObjBaseView() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._owner = null;
/**主体图像 */
_this._img = null;
_this._imgOffset = cc.v2();
_this._needMove = false;
_this._destroyed = false;
return _this;
//#endregion
//#region private method
//#endregion
}
Object.defineProperty(ObjBaseView.prototype, "owner", {
get: function () { return this._owner; },
enumerable: false,
configurable: true
});
//#region interface
ObjBaseView.prototype.onImgChanged = function () {
this.updateImg();
};
ObjBaseView.prototype.onDroped = function () {
this.setColliderEnable(false);
};
ObjBaseView.prototype.onDead = function () {
this._img.destroy();
this.node.destroy();
};
ObjBaseView.prototype.onHit = function () {
};
//#endregion
//#region life cycle
ObjBaseView.prototype.start = function () {
this.schedule(this.onLazyUpdate, 1 / 20);
};
ObjBaseView.prototype.init = function (owner, mapView) {
this._owner = owner;
this._owner.bindView(this);
this._img = this.node.getChildByName('img');
this._imgOffset.x = this._img.x;
this._imgOffset.y = this._img.y;
//分层显示
this._img.removeFromParent();
mapView.colliderLayer.addChild(this.node);
this.node.active = true;
mapView.blockImgLayer.addChild(this._img);
// this.updateImg();
this.onImgChanged();
this.onPositionChange(this._owner.pixelPos.x, this._owner.pixelPos.y);
};
ObjBaseView.prototype.onPreview = function () {
//预览状态下,在init后被调用
this._visible = true;
this._img.active = true;
this.setColliderEnable(false);
this.onVisibleChange();
};
ObjBaseView.prototype.update = function (dt) {
if (this._destroyed) {
return;
}
// let needMove = (this.node.position.y != this._owner.pixelPos.y);
this.onUpdateMoveState();
if (this._needMove) {
var speed = this._owner.droped ? 600 : Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 1).Value;
var step = -speed * dt;
var dis = this._owner.pixelPos.y - this.node.y;
if (Math.abs(step) >= Math.abs(dis)) {
step = dis;
}
this.onPositionChange(this._owner.pixelPos.x, this.node.position.y + step);
}
};
/**更改是否需要移动的接口,更改 _needMove变量 */
ObjBaseView.prototype.onUpdateMoveState = function () {
this._needMove = (this.node.position.y != this._owner.pixelPos.y);
};
// onEndContact(contact: cc.PhysicsContact, selfCollider: cc.Collider, otherCollider: cc.Collider) {
// if (otherCollider.node.name == "ball") {
// contact.disabled = true;
// this._owner.onCollisonToBall(otherCollider);
// }
// }
ObjBaseView.prototype.onBeginContact = function (contact, selfCollider, otherCollider) {
if (otherCollider.node.name == "ball") {
this._owner.onCollisonToBall(otherCollider);
}
};
ObjBaseView.prototype.onDestroy = function () {
this._destroyed = true;
this._owner = null;
this._img = null;
};
//#endregion
//#region public method
ObjBaseView.prototype.setColliderEnable = function (value) {
this.node.getComponent(cc.PhysicsCollider).enabled = value;
};
//#endregion
//#region children override
ObjBaseView.prototype.onLazyUpdate = function () {
};
ObjBaseView.prototype.onImageLoaded = function () {
};
ObjBaseView.prototype.updateImg = function () {
var _this = this;
if (this._owner.imgName != "") {
// this._img.active = true;
cc.resources.load("battle/" + this._owner.imgName, cc.SpriteFrame, function (err, spf) {
// const frame = (spf as cc.SpriteAtlas).getSpriteFrame(this._owner.iconName);
if (!err) {
if (!_this._destroyed) {
_this._img.getComponent(cc.Sprite).spriteFrame = spf;
_this.onImageLoaded();
}
}
else {
console.error(err.message);
}
});
}
else {
this._img.active = false;
}
};
ObjBaseView.prototype.onVisibleChange = function () {
};
ObjBaseView.prototype.onPositionChange = function (x, y) {
this._img.setPosition(x + this._imgOffset.x, y + this._imgOffset.y);
this.node.setPosition(x, y);
var visible = (this._owner.gridPos.y > this._owner.map.viewSplitRow);
if (this._visible != visible) {
this._visible = visible;
this.setColliderEnable(visible);
this._img.active = visible;
this.onVisibleChange();
}
};
ObjBaseView = __decorate([
ccclass
], ObjBaseView);
return ObjBaseView;
}(cc.Component));
exports.default = ObjBaseView;
cc._RF.pop();