| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
- import Random from "../utils/Random";
- import UiM, { PANEL_NAME } from "../manager/UiM";
- import PoolMgr, { NODEPOOLPREFABTYPE } from "../manager/PoolMgr";
- import Sciencen_M from "../utils/Sciencen_M";
- import Task from "./Task";
- import UsualCaidanNode from "./UsualCaidanNode";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class EffectNode extends cc.Component {
- static instance: EffectNode;
- @property(cc.Prefab)
- eftPrefabs: cc.Prefab[] = [];
- //@property(cc.Prefab)
- //coinPrefab: cc.Prefab = null;
- //@property(cc.Prefab)
- //goldPrefab: cc.Prefab = null;
- //@property(cc.Prefab)
- //expPrefab:cc.Prefab=null;
- @property(cc.Prefab)
- eftScreenCoin: cc.Prefab = null;
- @property(cc.Node)
- public eftTargets: cc.Node[] = [];
- //@property(cc.Node)
- //public goldTarget: cc.Node = null;
- //@property(cc.Node)
- //public coinTarget: cc.Node = null;
- //@property(cc.Node)
- //public expTarget:cc.Node=null;
- @property(cc.Camera)
- public mainCamera: cc.Camera = null;
- /**元宝icon*/
- @property(cc.Node)
- redMoneyIcon: cc.Node = null;
- /**金币icon*/
- @property(cc.Node)
- coinIcon: cc.Node = null;
- /**金币icon*/
- @property(cc.Node)
- expIcon: cc.Node = null;
- /**提示节点*/
- @property(cc.Node)
- tipNode: cc.Node = null;
- @property(cc.Node)
- carPosNode: cc.Node = null;
- @property(cc.Label)
- tipTxt: cc.Label = null;
- @property(sp.Skeleton)
- carDesAni: sp.Skeleton = null;
- @property(cc.Node)
- carDesTxtNode: cc.Node = null;
- @property(cc.Label)
- carDesTxt: cc.Label = null;
- @property(cc.Node)
- danBg: cc.Node = null;
- @property(sp.Skeleton)
- egg1: sp.Skeleton = null;
- @property(cc.Node)
- tipNode1: cc.Node = null;
- @property(cc.Label)
- tipTxt1: cc.Label = null;
- // LIFE-CYCLE CALLBACKS:
- onLoad() {
- EffectNode.instance = this;
- }
- start() {
- if (cc.winSize.height > 1500) {
- this.eftTargets[0].y += 90
- this.eftTargets[1].y += 90
- }
- }
- // update (dt) {}
- /**
- * @param type 类型,0 金币,1 红包币 5 活跃 6 骰子 7 遥控卡 8 双倍卡 9 经书 10 加速卡 11 抽奖券 12 夺宝券 13 天赋石 14 红包
- * @param num 特效数量
- * @param pos 起始位置
- * @param fly 是否飞行
- * @param endpos 飞行的目标坐标 只对 6-13 有效
- * @param cb 动画结束回调
- */
- public PlayCoinAnim(type: number = 0, num: number, pos: cc.Vec2, fly: boolean = true, endpos: cc.Vec2 = null, cb: Function = null) {
- let cam_pos;
- let tempPos3D = this.mainCamera.getWorldToScreenPoint(pos, cam_pos);
- pos = cc.v2(tempPos3D.x, tempPos3D.y);
- for (let i = 0; i < num; i++) {
- //FC:-
- //let copyCoin = cc.instantiate(this.eftPrefabs[type]);//type == 0 ? this.coinPrefab : this.goldPrefab);
- //FC:+ 对象池
- let copyCoin = null;
- if (type == 0) {
- copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Coin);
- } else if (type == 1) {
- copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Gold);
- } else if (type == 5) {
- copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.ActiveV);
- } else if (type == 6) {
- copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Dice);
- } else if (type == 7) {
- copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CtrlCard);
- } else if (type == 8) {
- copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.DoubleCard);
- } else if (type == 9) {
- copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Book);
- } else if (type == 10) {
- copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.SpeedCard);
- } else if (type == 11) {
- copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.DrawCard);
- } else if (type == 12) {
- copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.BaoCard);
- } else if (type == 13) {
- copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Talent);
- } else if (type == 14) {
- copyCoin = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.RedPackage);
- }
- copyCoin.setParent(this.node);
- copyCoin.scale = Random.Range(0.8, 1.2, false);
- copyCoin.angle = Random.Range(-45, 45, false);
- let dir = cc.v2(Random.Range(-1, 1, false), Random.Range(-1, 1, false));
- dir = dir.normalize();
- let deltaInit = cc.v2(Random.Range(10, 160, false) * dir.x, Random.Range(10, 160, false) * dir.y);
- //FC:-无效计算
- //let deltaEnd = cc.v2(Random.Range(250, 800, false) * dir.x, Random.Range(250, 800, false) * dir.y);
- let initPos = pos.add(deltaInit);
- //copyCoin.setPosition(initPos);
- copyCoin.setPosition(pos);
- this.FlyIn(type, copyCoin, initPos, fly, endpos, cb);
- }
- if (type == 5) {
- this.scheduleOnce(() => {
- UiM.Instance.taskNode.getComponent(Task).addActiveNum(num)
- }, 2)
- }
- }
- FlyIn(type: number = 0, target: cc.Node, end: cc.Vec2, fly: boolean, endpos: cc.Vec2 = null, cb: Function = null) {
- let ac1
- if (fly) {
- ac1 = cc.moveTo(Random.Range(0.3, 1, false), end).easing(cc.easeSineOut());
- }
- else {
- ac1 = cc.moveTo(Random.Range(0.3, 0.6, false), end).easing(cc.easeSineOut());
- }
- let callback = cc.callFunc(() => {
- //target.destroy();
- if (fly) {
- this.scheduleOnce(() => {
- if (type < 6 || type > 13) {
- if (endpos != null)
- this.FlyOut(type, target, endpos, cb);
- else
- this.FlyOut(type, target, (this.eftTargets[type]).getPosition(), cb);
- } else {
- if (endpos != null)
- this.FlyOut(type, target, endpos, cb);
- else
- this.FlyOut(type, target, (this.eftTargets[0]).getPosition(), cb);
- }
- }, 0);
- }
- else {
- if (type == 0) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Coin, target);
- this.CoinIconAni();
- }
- else if (type == 1) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Gold, target);
- this.RedMoneyIconAni();
- }
- else if (type == 5) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.ActiveV, target);
- }
- }
- });
- let total = cc.sequence(ac1, callback);
- target.runAction(total);
- }
- FlyOut(type: number = 0, target: cc.Node, end: cc.Vec2, cb: Function = null) {
- let dur = Random.Range(0.3, 1, false);
- target.runAction(cc.scaleTo(dur, 0.8));
- let ac1 = cc.moveTo(dur, end).easing(cc.easeSineOut());
- let callback = cc.callFunc(() => {
- //FC:-
- //target.destroy();
- if (type == 0) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Coin, target);
- this.CoinIconAni();
- }
- else if (type == 1) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Gold, target);
- this.RedMoneyIconAni();
- }
- else if (type == 5) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.ActiveV, target);
- }
- else if (type == 6) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Dice, target);
- }
- else if (type == 7) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.CtrlCard, target);
- }
- else if (type == 8) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.DoubleCard, target);
- }
- else if (type == 9) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Book, target);
- }
- else if (type == 10) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.SpeedCard, target);
- }
- else if (type == 11) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.DrawCard, target);
- }
- else if (type == 12) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.BaoCard, target);
- }
- else if (type == 13) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.Talent, target);
- }
- else if (type == 14) {
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.RedPackage, target);
- }
- //type == 0 ? this.CoinIconAni() : this.RedMoneyIconAni();
- if (cb != null) {
- cb();
- }
- });
- let total = cc.sequence(ac1, callback);
- target.runAction(total);
- }
- /**
- * 经验特效
- * @param type 1 经验 2 每日提现
- */
- PlayExpEffect(pos: cc.Vec2, type = 1) {
- //FC:-
- //let eftcopy = cc.instantiate(this.expPrefab);
- //FC:+ 对象池
- let eftcopy = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CarExpEft);
- eftcopy.setParent(this.node);
- eftcopy.setPosition(pos);
- eftcopy.scale = 1.5;
- //eftcopy.getComponent(cc.ParticleSystem).playOnLoad = true;
- //FC:+
- eftcopy.getComponent(cc.ParticleSystem).resetSystem();
- // console.log("ExpPOS:", pos);
- let tarPos = null
- if (type == 1) {
- tarPos = this.eftTargets[2]
- }
- else if (type == 2) {
- tarPos = this.eftTargets[4]
- }
- cc.tween(eftcopy).to(0.7, { position: cc.v2(tarPos.x, tarPos.y) })
- .call(() => {
- //FC:-
- //eftcopy.destroy()
- //FC:+ 对象池
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.CarExpEft, eftcopy);
- })
- .start();
- }
- redIconAniEnd: boolean = true;
- /**
- * 获取元宝 元宝icon动画
- */
- RedMoneyIconAni() {
- if (this.redIconAniEnd) {
- this.redIconAniEnd = false;
- cc.tween(this.redMoneyIcon).to(0.1, { scale: 1.2 }).to(0.05, { scale: 1 }).call(() => this.redIconAniEnd = true).start();
- }
- }
- coinIconAniEnd: boolean = true;
- /**
- * 获取金币 金币icon动画
- */
- CoinIconAni() {
- if (this.coinIconAniEnd) {
- this.coinIconAniEnd = false;
- cc.tween(this.coinIcon).to(0.1, { scale: 1.2 }).to(0.05, { scale: 1 }).call(() => this.coinIconAniEnd = true).start();
- }
- }
- expIconAniEnd: boolean = true;
- /**
- * 获取经验值 经验头像动画
- */
- ExpIconAni() {
- if (this.expIconAniEnd) {
- this.expIconAniEnd = false;
- cc.tween(this.expIcon).to(0.1, { scale: 1.2 }).to(0.05, { scale: 1 }).call(() => this.expIconAniEnd = true).start();
- }
- }
- /**
- * 提示语显示
- */
- PlayTip(content: string) {
- this.tipNode.stopAllActions();
- this.tipNode.setPosition(cc.v2(0, 0));
- this.tipNode.active = true;
- this.tipNode.opacity = 255;
- this.tipTxt.string = content;
- let ac1 = cc.moveTo(0.35, cc.v2(0, this.node.height / 4)).easing(cc.easeSineOut());
- let wait = cc.delayTime(1.5);
- let fade = cc.fadeOut(1).easing(cc.easeQuinticActionIn());
- let backcall = cc.callFunc(() => this.tipNode.active = false);
- let total = cc.sequence(ac1, wait, fade, backcall);
- this.tipNode.runAction(total);
- }
- PlayTipSimple(content: string) {
- this.tipTxt1.string = content
- this.tipNode1.active = true
- this.tipNode1.scale = 0
- this.tipNode1.opacity = 0
- cc.tween(this.tipNode1)
- .to(0.35, { scale: 1, opacity: 255 })
- .delay(1.5)
- .to(0.35, { opacity: 0 })
- .start()
- }
- /**
- * 提示语显示
- */
- PlayProTip(content: string) {
- this.tipNode.stopAllActions();
- this.tipNode.setPosition(cc.v2(0, 0));
- this.tipNode.active = true;
- this.tipNode.opacity = 255;
- this.tipTxt.string = content;
- let ac1 = cc.moveTo(0.35, cc.v2(0, this.node.height / 4)).easing(cc.easeSineOut());
- let wait = cc.delayTime(1.5);
- let fade = cc.fadeOut(1).easing(cc.easeQuinticActionIn());
- let backcall = cc.callFunc(() => this.tipNode.active = false);
- let total = cc.sequence(ac1, wait, fade, backcall);
- this.tipNode.runAction(total);
- }
- /**垃圾回收动画*/
- PlayTrashAni(num: number) {
- //FC:-
- //let eft = cc.instantiate(this.carDesEft);
- //FC:+
- let eft = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CarDesEft);
- eft.scale = 1.2;
- eft.setParent(this.node);
- eft.setPosition(this.carPosNode.getPosition());
- eft.getComponent(sp.Skeleton).setAnimation(0, 'animation', false);
- this.carDesAni.node.setPosition(this.carPosNode.getPosition());
- this.carDesAni.node.active = true;
- this.carDesAni.setAnimation(0, 'animation', false);
- this.scheduleOnce(() => {
- //FC:-
- //eft.destroy();
- //FC:+
- PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.CarDesEft, eft);
- this.carDesAni.node.active = false;
- }, 1);
- this.carDesTxtNode.setPosition(this.carPosNode.getPosition());
- this.carDesTxtNode.active = true;
- this.carDesTxt.string = Sciencen_M.instance.format(num.toString());
- cc.tween(this.carDesTxtNode).to(0.5, { position: cc.v2(0, this.carPosNode.getPosition().y + 110) }).call(() => this.carDesTxtNode.active = false).start();
- }
- /**播放全屏金币例子特效*/
- PlayScreenCoin() {
- let eft = cc.instantiate(this.eftScreenCoin);
- eft.parent = this.node;
- eft.setPosition(0, cc.winSize.height / 2);
- }
- /** 彩蛋进入 */
- playEggIn() {
- this.danBg.active = true
- // this.egg.active = true
- // this.egg.setPosition(cc.v2(-600, 76))
- // cc.tween(this.egg)
- // // .bezierTo(1, cc.v2(-600, 300), cc.v2(-170, 1200), cc.v2(-170, 300))
- // // .to(0.1, { angle: 10 })
- // // .to(0.2, { angle: -10 })
- // // .to(0.2, { angle: 10 })
- // // .to(0.1, { angle: 0 })
- // // .delay(0.5)
- // .bezierTo(1, cc.v2(-600, 76), cc.v2(0, 1000), cc.v2(0, 76))
- // .to(0.1, { angle: 10 })
- // .to(0.2, { angle: -10 })
- // .to(0.2, { angle: 10 })
- // .to(0.1, { angle: 0 })
- // .delay(0.5)
- // .call(() => {
- // this.danBg.active = false
- // UiM.Instance.onPanel(PANEL_NAME.UsualCaidanNode, false, () => {
- // UiM.Instance.usualCaidanNode.getComponent(UsualCaidanNode).init()
- // this.egg.active = false
- // })
- // })
- // .start()
- this.egg1.node.active = true
- this.egg1.setAnimation(0, 'animation', false)
- this.scheduleOnce(() => {
- // this.danBg.active = false
- this.egg1.node.active = false
- UiM.Instance.onPanel(PANEL_NAME.UsualCaidanNode, false, () => {
- UiM.Instance.usualCaidanNode.getComponent(UsualCaidanNode).init()
- this.danBg.active = false
- })
- }, 1.5)
- }
- }
|