|
@@ -1,4 +1,4 @@
|
|
|
-import { _decorator, BoxCollider2D, CircleCollider2D, Color, Component, ERigidBody2DType, instantiate, PolygonCollider2D, RigidBody2D, Sprite, tween, UIOpacity, view, Node, isValid } from 'cc';
|
|
|
+import { _decorator, BoxCollider2D, CircleCollider2D, Color, Component, ERigidBody2DType, instantiate, PolygonCollider2D, RigidBody2D, Sprite, tween, UIOpacity, view, Node, isValid, find } from 'cc';
|
|
|
import { EventDispatcher } from '../../core_tgx/easy_ui_framework/EventDispatcher';
|
|
|
import { CarColorHex, CarColors } from './CarColorsGlobalTypes';
|
|
|
import { HoleComponent } from './Components/HoleComponent';
|
|
@@ -10,13 +10,23 @@ const { ccclass, property } = _decorator;
|
|
|
|
|
|
@ccclass('ElementAction')
|
|
|
export class ElementAction extends Component {
|
|
|
- ele_color: CarColors
|
|
|
+ ele_color: CarColors;
|
|
|
+ parking: Node;
|
|
|
+
|
|
|
start() {
|
|
|
+ this.parking = find('Canvas/Scene/Parkings')!;
|
|
|
+
|
|
|
EventDispatcher.instance.on(GameEvent.EVENT_CHECK_ELEMENT_CHILDREN, this.checkElementChildren, this);
|
|
|
}
|
|
|
|
|
|
update(deltaTime: number) {
|
|
|
- let currentPosition = this.node.getPosition().clone();
|
|
|
+ const currentPosition = this.node.getPosition().clone();
|
|
|
+ const worldPos = this.node.getWorldPosition();
|
|
|
+
|
|
|
+ if (worldPos.y <= this.parking.getWorldPosition().y) {
|
|
|
+ EventDispatcher.instance.emit(GameEvent.EVENT_UPDATE_LAYER);
|
|
|
+ }
|
|
|
+
|
|
|
if (currentPosition.y < - view.getVisibleSize().height) {
|
|
|
this.removeElement();
|
|
|
}
|
|
@@ -26,7 +36,6 @@ export class ElementAction extends Component {
|
|
|
if (isValid(this.node)) {
|
|
|
this.node.removeFromParent();
|
|
|
this.node.destroy();
|
|
|
- EventDispatcher.instance.emit(GameEvent.EVENT_UPDATE_LAYER);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -38,7 +47,7 @@ export class ElementAction extends Component {
|
|
|
const pins = this.node.getComponentsInChildren(PinComponent)!;
|
|
|
// console.log('检测是否还有钉子:', pins.length)
|
|
|
if (pins.length == 0) {
|
|
|
- console.log("没有钉子 Element刚体变成动力学");
|
|
|
+ // console.log("没有钉子 Element刚体变成动力学");
|
|
|
this.node.getComponent(RigidBody2D).type = ERigidBody2DType.Dynamic;
|
|
|
}
|
|
|
}
|
|
@@ -56,12 +65,6 @@ export class ElementAction extends Component {
|
|
|
public init_element(group_id: number, ele_color: CarColors) {
|
|
|
this.ele_color = ele_color;
|
|
|
this.node.getComponent(RigidBody2D).group = group_id;
|
|
|
- this.node.getComponents(BoxCollider2D).forEach(element => {
|
|
|
- element.group = group_id;
|
|
|
- });
|
|
|
- this.node.getComponents(CircleCollider2D).forEach(element => {
|
|
|
- element.group = group_id;
|
|
|
- });
|
|
|
this.node.getComponents(PolygonCollider2D).forEach(element => {
|
|
|
element.group = group_id;
|
|
|
});
|