Commit 6afb5718 authored by Vũ Gia Vương's avatar Vũ Gia Vương

add collider to Fragment

parent 0c905f64
This diff is collapsed.
...@@ -19,4 +19,6 @@ export const PLAY_ANIM_NUT4 = 'PLAY_ANIM_NUT4'; ...@@ -19,4 +19,6 @@ export const PLAY_ANIM_NUT4 = 'PLAY_ANIM_NUT4';
export const ROTATE_GUILD = 'ROTATE_GUILD'; export const ROTATE_GUILD = 'ROTATE_GUILD';
export const BEAT_GUILD = 'BEAT_GUILD'; export const BEAT_GUILD = 'BEAT_GUILD';
export const STOP_GUILD_ROTATE = 'STOP_GUILD_ROTATE'; export const STOP_GUILD_ROTATE = 'STOP_GUILD_ROTATE';
export const STOP_GUILD_TAP = 'STOP_GUILD_TAP'; export const STOP_GUILD_TAP = 'STOP_GUILD_TAP';
\ No newline at end of file
export const CHECK_TOUCH = 'CHECK_TOUCH';
\ No newline at end of file
import FragmentController from "./FragmentController";
const { ccclass, property } = cc._decorator;
@ccclass
export default class BreakingBottleController extends cc.Component {
private _body: cc.Node = null;
private _lid: cc.Node = null;
private _fragmentsBody: cc.Node[] = [];
private _fragmentsLid: cc.Node[] = [];
private _fragmentsAll: cc.Node[] = [];
protected onLoad(): void {
[this._body, this._lid] = this.node.children;
this._fragmentsBody = this._body.children;
this._fragmentsLid = this._lid.children;
this._fragmentsAll = [...this._fragmentsBody, ...this._fragmentsLid];
// console.log('this._fragmentsAll', this._fragmentsAll.map(item => item.position.toString()));
// this._fragmentsAll.forEach(item => {
// item.addComponent(FragmentController);
// })
}
}
{
"ver": "1.1.0",
"uuid": "6fcd7f71-d097-4f64-a0f3-52bd35d14332",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
import { eventTarget, CHECK_TOUCH } from "../Events";
const { ccclass, property } = cc._decorator;
@ccclass
export default class FragmentController extends cc.Component {
private _collider: cc.PolygonCollider = null;
onLoad() {
this._collider = this.node.getComponent(cc.PolygonCollider);
console.log('this._collider', this._collider.points.length)
eventTarget.on(CHECK_TOUCH, this.checkTouch, this);
}
private checkTouch(point: cc.Vec2) {
// console.log('point', point.toString(), this.node.position.toString());
const pos = point.clone().subtract(cc.v2(this.node.position.x, this.node.position.y));
let isInside = cc.Intersection.pointInPolygon(pos, this._collider.points);
// console.log('this._collider.points', this._collider.points.map(i => i.toString()));
if (isInside) {
console.log('isInside', isInside, pos.toString(), this.node.name)
}
}
}
{
"ver": "1.1.0",
"uuid": "ad9b7183-781d-4ae6-ac93-79add38d57c7",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
import { eventTarget, CHECK_TOUCH } from "../Events";
const { ccclass, property } = cc._decorator;
@ccclass
export default class BreakingBottleScreen extends cc.Component {
@property(cc.Node)
private spriteNode: cc.Node = null;
onLoad() {
this.node.position = cc.v3(0, 0);
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
}
private onTouchStart(event: cc.Event.EventTouch) {
const pos = event.getLocation();
const nodePos = this.node.convertToNodeSpaceAR(pos);
this.spriteNode.position = cc.v3(nodePos.x, nodePos.y);
eventTarget.emit(CHECK_TOUCH, nodePos);
}
}
{
"ver": "1.1.0",
"uuid": "90267826-75d6-4f90-b056-fde22260947a",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ 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