123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- import FqLogin from "../../login/FqLogin";
- import { AudioMgr } from "../../main/ViewManage";
- import BaseEvent from "../fight/evnet/base/BaseEvent";
- const SpineName = {
- CLOSE: "close",
- OPEN: "open"
- }
- /**
- * 多组按钮控制开门
- */
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class JG0111 extends BaseEvent {
- @property({
- displayName: '替换的图片',
- type: cc.Sprite,
- })
- mIcon: cc.Sprite = null;
- @property({
- displayName: '未踩上图片',
- type: cc.SpriteFrame,
- })
- mIcon0: cc.SpriteFrame = null;
- @property({
- displayName: '踩上后的图片',
- type: cc.SpriteFrame,
- })
- mIcon1: cc.SpriteFrame = null;
- /**
- * 控制的栅栏机关
- */
- @property({
- displayName: '其它开关',
- type: [cc.Node],
- })
- mButtons: Array<cc.Node> = [];
- /**
- * 控制的栅栏机关
- */
- @property({
- displayName: '控制的机关',
- type: [cc.Node],
- })
- mFenceTrigger: Array<cc.Node> = [];
- /**
- * 是否选中
- */
- public isHang = false;
- /**
- * 机关是否已经结束
- */
- public isOver = false;
- private count = 0;
- onLoad(){
- super.onLoad();
- this.node.zIndex = -9999;
- }
- onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
- if (other.node.group != 'bullet') {
- this.count++
- this.onBegin(self.tag)
- }
- }
- onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
- if (other.node.group != 'bullet') {
- this.count--
- if (this.count <= 0) {
- this.count = 0;
- this.onEnd(self.tag)
- }
- }
- }
- onBegin(tag: number) {
- this.isHang = true;
- this.mIcon.spriteFrame = this.mIcon1;
- this.checkOpen();
- }
- onEnd(tag: number) {
- this.isHang = false
- this.mIcon.spriteFrame = this.mIcon0
- this.isOver = false;
- for (let i = 0; i < this.mFenceTrigger.length; i++) {
- const element = this.mFenceTrigger[i];
- // element.active = true;
- this.showFence(element, SpineName.CLOSE);
- element.getComponent(cc.PhysicsBoxCollider).enabled = true;
- }
- }
- private checkOpen() {
- if (this.isOver) {
- return
- }
- //检查其它开关是否打开
- for (let i = 0; i < this.mButtons.length; i++) {
- const element = this.mButtons[i];
- let fdb = element.getComponent(JG0111)
- if (!fdb.isHang) return
- }
- this.isOver = true;
- this.pause();
- this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
- cc.tween(this.node).sequence(
- cc.callFunc(() => {
- for (let i = 0; i < this.mFenceTrigger.length; i++) {
- const element = this.mFenceTrigger[i];
- this.showFence(element, SpineName.OPEN);
- element.zIndex = -9999;
- }
- this.ff.main.playerEffectByPath(AudioMgr.openDoor);
- }),
- cc.delayTime(1),
- cc.callFunc(() => {
- this.resume()
- for (let i = 0; i < this.mFenceTrigger.length; i++) {
- const element = this.mFenceTrigger[i];
- // element.active = false;
- element.getComponent(cc.PhysicsBoxCollider).enabled = false;
- }
- })
- ).start();
- })
- }
- private showFence(element, action) {
- let nodes = element.children;
- for (let i = 0; i < nodes.length; i++) {
- const element = nodes[i];
- let spine:sp.Skeleton = element.getComponent(sp.Skeleton);
- if (spine) {
- spine.setAnimation(0, action, false);
- }
- }
- }
- }
|