|
|
@@ -0,0 +1,182 @@
|
|
|
+import { RewardType } from "../../game/data/GameData";
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description 获取道具特效
|
|
|
+ * @author kaka
|
|
|
+ * */
|
|
|
+const { ccclass } = cc._decorator;
|
|
|
+
|
|
|
+@ccclass
|
|
|
+export default class FlySystem2 extends cc.Component {
|
|
|
+ onLoad() {
|
|
|
+ mk.fly2 = this;
|
|
|
+ }
|
|
|
+
|
|
|
+ private is_new_cb = true;
|
|
|
+ /**
|
|
|
+ * @param type 类型 道具id 10001,10002
|
|
|
+ * @param num 特效数量
|
|
|
+ * @param pos 起始位置
|
|
|
+ * @param endpos 飞行目标的世界坐标 或目标对象路径 如果为"",则飞到主界面货币按钮处 默认""
|
|
|
+ * @param cb 动画结束回调
|
|
|
+ */
|
|
|
+ public async PlayCoinAnim(type: number = 0, num: number, startpos_node: cc.Node, endpos: cc.Vec2 | string = '', item_cb: Function = null, isScale: number = -1, averageValue: number = -1) {
|
|
|
+ for (let i = 0; i < num; i++) {
|
|
|
+ let copyCoin = await mk.pool.getPrefab('game/prefab/coin');
|
|
|
+ let url = 'game/texture/coin/' + type;
|
|
|
+ let sf = await mk.loader.load(url, cc.SpriteFrame);
|
|
|
+ copyCoin.getComponent(cc.Sprite).spriteFrame = sf;
|
|
|
+ copyCoin.setParent(this.node);
|
|
|
+ if(isScale != -1)
|
|
|
+ {
|
|
|
+ copyCoin.scale = isScale;
|
|
|
+ }else{
|
|
|
+ copyCoin.scale = mk.math.random(0.56, 0.84, false);
|
|
|
+ }
|
|
|
+ copyCoin.angle = mk.math.random(-45, 45, false);
|
|
|
+ let dir = cc.v2(mk.math.random(-1, 1, false), mk.math.random(-1, 1, false));
|
|
|
+ dir = dir.normalize();
|
|
|
+ let deltaInit = cc.v2(mk.math.random(10, 160, false) * dir.x, mk.math.random(10, 160, false) * dir.y);
|
|
|
+ let pos = new cc.Vec2(0, -300);
|
|
|
+ if(startpos_node)
|
|
|
+ {
|
|
|
+ let world_Pos = startpos_node.parent.convertToWorldSpaceAR(startpos_node.getPosition());
|
|
|
+ pos = this.node.convertToNodeSpaceAR(world_Pos);
|
|
|
+ }
|
|
|
+ let initPos = pos.add(deltaInit);
|
|
|
+ copyCoin.setPosition(pos);
|
|
|
+
|
|
|
+ this.FlyIn(type, copyCoin, initPos, endpos, item_cb, averageValue);
|
|
|
+ }
|
|
|
+ this.is_new_cb = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private FlyIn(type: number, target: cc.Node, end: cc.Vec2, endpos: cc.Vec2 | string = null, item_cb: Function = null, averageValue: number = -1) {
|
|
|
+ cc.tween(target)
|
|
|
+ .to(mk.math.random(0.3, 0.6, false), { position: cc.v3(end) }, cc.easeSineInOut())
|
|
|
+ .call(() => {
|
|
|
+ this.FlyOut(type, target, endpos, item_cb, averageValue);
|
|
|
+ })
|
|
|
+ .start();
|
|
|
+ }
|
|
|
+
|
|
|
+ private FlyOut(type: number, target: cc.Node, end: cc.Vec2 | string, item_cb: Function = null, averageValue: number = -1) {
|
|
|
+ let dur = mk.math.random(0.3, 1, false);
|
|
|
+ cc.tween(target)
|
|
|
+ .to(dur, { scale: 0.8 })
|
|
|
+ .start();
|
|
|
+
|
|
|
+ console.log('---');
|
|
|
+ let end_pos: cc.Vec2 = null;
|
|
|
+ let end_node: cc.Node = null;
|
|
|
+ if (typeof end === 'string') {
|
|
|
+ if (end == '') {
|
|
|
+ let url = ''
|
|
|
+ if (type == RewardType.redBag) {
|
|
|
+ url = 'Canvas/界面层/game/node_ui/顶部个人信息/提现按钮/icon_zb';
|
|
|
+ }
|
|
|
+ else if (type == RewardType.pigRmb) {
|
|
|
+ url = 'Canvas/界面层/game/node_ui/顶部个人信息/金猪币按钮/icon_zb';
|
|
|
+ } else {
|
|
|
+ // 未知类型
|
|
|
+ mk.pool.return('game/prefab/coin', target);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ end = url;
|
|
|
+ }
|
|
|
+
|
|
|
+ end_node = cc.find(end as string);
|
|
|
+ let world_pos = end_node.parent.convertToWorldSpaceAR(end_node.getPosition());
|
|
|
+ end_pos = this.node.convertToNodeSpaceAR(world_pos);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ end_pos = this.node.convertToNodeSpaceAR(end);
|
|
|
+ }
|
|
|
+
|
|
|
+ cc.tween(target)
|
|
|
+ .to(dur, { position: cc.v3(end_pos) }, cc.easeSineOut())
|
|
|
+ .call(() => {
|
|
|
+ console.log('end_pos ', target.position)
|
|
|
+
|
|
|
+ // if (end_node) {
|
|
|
+ // cc.tween(end_node).to(0.1, { scale: 1.2 }).to(0.05, { scale: 1 }).start();
|
|
|
+ // }
|
|
|
+ if(averageValue != -1)
|
|
|
+ {
|
|
|
+ this.showLabStrChange(averageValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item_cb != null) {
|
|
|
+ this.is_new_cb && item_cb();
|
|
|
+ this.is_new_cb = false;
|
|
|
+ }
|
|
|
+ //this.iconScale(type);
|
|
|
+
|
|
|
+ mk.pool.return('game/prefab/coin', target);
|
|
|
+ })
|
|
|
+ .start();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * icon缩放动画
|
|
|
+ * @param type icon类型
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+ private iconScale(type: number) {
|
|
|
+ let node;
|
|
|
+ if (type === 1) {
|
|
|
+ node = gData.gameData.gameStyle.lbl_redMoney.node;
|
|
|
+ } else if (type === 3) {
|
|
|
+ node = gData.gameData.gameStyle.lbl_redMoney.node;
|
|
|
+ }
|
|
|
+ if (!node) return;
|
|
|
+ cc.tween(node).to(0.1, { scale: 1.3 }).to(0.05, { scale: 1 }).start();
|
|
|
+ }
|
|
|
+
|
|
|
+ private showLabStrChange(value: number)
|
|
|
+ {
|
|
|
+ if(gData.gameData.gameStyle.lbl_redMoney)
|
|
|
+ {
|
|
|
+ gData.gameData.gameData.redMoney += value;
|
|
|
+ //gData.gameData.gameStyle.lbl_redMoney.string = gData.gameData.gameData.redMoney.toString();
|
|
|
+ //cc.tween(gData.gameData.gameStyle.lbl_redMoney.node).to(0.1, { scale: 1.2 }).to(0.05, { scale: 1 }).start();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 节点飞行动画
|
|
|
+ * @param startTarget 飞行节点
|
|
|
+ * @param endTarget 飞行终点位置的节点
|
|
|
+ * @param duration 飞行时间
|
|
|
+ * @param callFuc 回调
|
|
|
+ * @param offsetPos 相对终点的偏移值
|
|
|
+ */
|
|
|
+
|
|
|
+ public playFlyAni(startTarget: cc.Node, cloneTarget: cc.Node, endTarget: cc.Node, duration: number, callFuc: Function|null = null, offsetPos: cc.Vec3 = cc.Vec3.ZERO)
|
|
|
+ {
|
|
|
+ let worldPos = startTarget.parent.convertToWorldSpaceAR(startTarget.getPosition());
|
|
|
+ let pos = endTarget.parent.convertToNodeSpaceAR(worldPos);
|
|
|
+ let newNode = cc.instantiate(cloneTarget);
|
|
|
+ newNode.active = true;
|
|
|
+ newNode.setParent(endTarget.parent);
|
|
|
+ newNode.setPosition(pos);
|
|
|
+ //cc.Tween.stopAllByTarget(newNode);
|
|
|
+
|
|
|
+ // let endWorldPos = endTarget.parent.convertToWorldSpaceAR(endTarget.getPosition());
|
|
|
+ // let endPos = this.node.convertToNodeSpaceAR(endWorldPos);
|
|
|
+
|
|
|
+ //测试代码
|
|
|
+ //let p = endTarget.getPosition();
|
|
|
+
|
|
|
+ let endPos = cc.Vec3.ZERO;
|
|
|
+ endPos.add(offsetPos, endPos);
|
|
|
+
|
|
|
+ cc.tween(newNode).to(duration, { position: cc.v3(endPos) }, cc.easeSineOut()).call(()=>{
|
|
|
+ if(callFuc)
|
|
|
+ {
|
|
|
+ callFuc();
|
|
|
+ }
|
|
|
+ newNode.destroy();
|
|
|
+ }).start();
|
|
|
+ }
|
|
|
+}
|