|
@@ -1,4 +1,4 @@
|
|
|
-import { _decorator, Node, EventTouch, Rect, UITransform, Sprite, SpriteFrame, Vec2, instantiate, Vec3, Component } from 'cc';
|
|
|
+import { _decorator, Node, EventTouch, Rect, UITransform, Sprite, SpriteFrame, Vec2, instantiate, Vec3, Component } from 'cc';
|
|
|
import { resMgr } from '../../Frames/ResourcesMgr';
|
|
|
import { Role } from './Role';
|
|
|
import { dataMgr } from '../../Frames/DataManager';
|
|
@@ -7,6 +7,7 @@ import { ModulerBase } from '../GameFrameWork/ModulerBase';
|
|
|
import { MyRole } from './GameScene/MyRole';
|
|
|
import { Card } from './Card';
|
|
|
import { Bottom } from './GameScene/Bottom';
|
|
|
+import { PoolManager } from '../GameFrameWork/NodePool/PoolManager';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@ccclass('TouchGame')
|
|
@@ -36,6 +37,9 @@ export class TouchGame extends ModulerBase {
|
|
|
}
|
|
|
|
|
|
protected start(): void {
|
|
|
+ //创建6个预制体
|
|
|
+ PoolManager.instance.registerPool(resMgr.getPrefab("Role"), 6);
|
|
|
+
|
|
|
this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
|
|
|
this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
|
|
|
this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
|
|
@@ -51,7 +55,7 @@ export class TouchGame extends ModulerBase {
|
|
|
if (box.contains(pos)) {
|
|
|
this._clickedNode = element;
|
|
|
this._clickedNodeCom = this._clickedNode.getComponent(Card);
|
|
|
- if(!this._clickedNodeCom.disabled && this._clickedNodeCom.clickable){
|
|
|
+ if (!this._clickedNodeCom.disabled && this._clickedNodeCom.clickable) {
|
|
|
const img: SpriteFrame = element.getChildByName("Sprite").getComponent(Sprite).spriteFrame;
|
|
|
if (!img) {
|
|
|
this._isDragging = false;
|
|
@@ -65,7 +69,7 @@ export class TouchGame extends ModulerBase {
|
|
|
this.setDragNodePosition(pos);
|
|
|
}
|
|
|
break; // 找到一个就停止遍历
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -105,7 +109,7 @@ export class TouchGame extends ModulerBase {
|
|
|
for (const element of this._load.children) {
|
|
|
if (element.name !== "Roles") {
|
|
|
const box = element.getComponent(UITransform).getBoundingBoxToWorld();
|
|
|
- if (box.contains(new Vec2(pos.x,pos.y))) {
|
|
|
+ if (box.contains(new Vec2(pos.x, pos.y))) {
|
|
|
this._highLightIdx = element.getSiblingIndex();
|
|
|
if (this._highLightIdx >= 6) {
|
|
|
this._hideNode();
|
|
@@ -115,7 +119,10 @@ export class TouchGame extends ModulerBase {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- const role: Node = instantiate(resMgr.getPrefab("Role"));
|
|
|
+
|
|
|
+ //从NodePool里获取一个Node
|
|
|
+ const role: Node = PoolManager.instance.get(resMgr.getPrefab("Role"));
|
|
|
+ //const role: Node = instantiate(resMgr.getPrefab("Role"));
|
|
|
role.parent = this._load.getChildByName("Roles");
|
|
|
|
|
|
const roleTS: Role = role.getComponent(MyRole);
|
|
@@ -130,7 +137,7 @@ export class TouchGame extends ModulerBase {
|
|
|
this._clickedNode.getComponent(Card).aniPlay();
|
|
|
this._hideNode();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private _hideNode() {
|
|
|
this._dragNode.active = false;
|
|
|
this._dragNode.getComponent(Sprite).spriteFrame = null;
|