Commit 99f7e199 authored by Vũ Gia Vương's avatar Vũ Gia Vương

done

parent d2272422
This diff is collapsed.
...@@ -4,7 +4,13 @@ const { ccclass, property } = cc._decorator; ...@@ -4,7 +4,13 @@ const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class FragmentJarController extends cc.Component { export default class FragmentJarController extends cc.Component {
@property(cc.Node)
private fragmentLink: cc.Node = null;
@property
private isBottom: boolean = false;
private _physicsCollider: cc.PhysicsPolygonCollider = null; private _physicsCollider: cc.PhysicsPolygonCollider = null;
private _physicsColliderFragmentLink: cc.PhysicsPolygonCollider = null;
private _rg: cc.RigidBody = null; private _rg: cc.RigidBody = null;
private _siblingIndex: number = 0; private _siblingIndex: number = 0;
private _isDropped: boolean = false; private _isDropped: boolean = false;
...@@ -13,6 +19,7 @@ export default class FragmentJarController extends cc.Component { ...@@ -13,6 +19,7 @@ export default class FragmentJarController extends cc.Component {
onLoad() { onLoad() {
this._physicsCollider = this.node.getComponent(cc.PhysicsPolygonCollider); this._physicsCollider = this.node.getComponent(cc.PhysicsPolygonCollider);
this._physicsColliderFragmentLink = this.fragmentLink && this.fragmentLink.getComponent(cc.PhysicsPolygonCollider);
this._rg = this.node.getComponent(cc.RigidBody); this._rg = this.node.getComponent(cc.RigidBody);
this._siblingIndex = this.node.getSiblingIndex(); this._siblingIndex = this.node.getSiblingIndex();
this._slots = this.node.children; this._slots = this.node.children;
...@@ -36,14 +43,21 @@ export default class FragmentJarController extends cc.Component { ...@@ -36,14 +43,21 @@ export default class FragmentJarController extends cc.Component {
} }
private checkTouch(point: cc.Vec2) { private checkTouch(point: cc.Vec2) {
if (this._isDropped) { if (this._isDropped || this.isBottom) {
return; return;
} }
const pos = point.clone().subtract(cc.v2(this.node.position.x, this.node.position.y)); const pos = point.clone().subtract(cc.v2(this.node.position.x, this.node.position.y));
let isInside = cc.Intersection.pointInPolygon(pos, this._physicsCollider.points); const isInside = cc.Intersection.pointInPolygon(pos, this._physicsCollider.points);
let isInsideFragmentLink = false;
if (this._physicsColliderFragmentLink) {
const posFragmentLink = point.clone().subtract(cc.v2(this.fragmentLink.position.x, this.fragmentLink.position.y));
isInsideFragmentLink = cc.Intersection.pointInPolygon(posFragmentLink, this._physicsColliderFragmentLink.points);
console.log('isInside', isInside, isInsideFragmentLink, this.node.name, this._physicsColliderFragmentLink.points.length)
}
if (!isInside) { if (!isInside && !isInsideFragmentLink) {
return; return;
} }
...@@ -62,7 +76,6 @@ export default class FragmentJarController extends cc.Component { ...@@ -62,7 +76,6 @@ export default class FragmentJarController extends cc.Component {
this._isDropped = true; this._isDropped = true;
const pos = this.node.position; const pos = this.node.position;
this.node.setSiblingIndex(-1); this.node.setSiblingIndex(-1);
// eventTarget.emit(CHECK_FRAGMENT, this.node.name);
eventTarget.emit(CHECK_FRAGMENT, this.node); eventTarget.emit(CHECK_FRAGMENT, this.node);
cc.tween(this.node) cc.tween(this.node)
......
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