| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import { RewardType } from "../../game/data/GameData";
- /**
- * @description 获取道具特效
- * @author kaka
- * */
- const { ccclass } = cc._decorator;
- @ccclass
- export default class FlySystem extends cc.Component {
- onLoad() {
- mk.fly = 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, pos: cc.Vec2, endpos: cc.Vec2 | string = '', item_cb: Function = null) {
- 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);
- 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 initPos = pos.add(deltaInit);
- copyCoin.setPosition(pos);
- this.FlyIn(type, copyCoin, initPos, endpos, item_cb);
- }
- this.is_new_cb = true;
- }
- private FlyIn(type: number, target: cc.Node, end: cc.Vec2, endpos: cc.Vec2 | string = null, item_cb: Function = null) {
- 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);
- })
- .start();
- }
- private FlyOut(type: number, target: cc.Node, end: cc.Vec2 | string, item_cb: Function = null) {
- let dur = mk.math.random(0.3, 1, false);
- cc.tween(target)
- .to(dur, { scale: 0.8 })
- .start();
- 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_hb';
- }
- 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)
- mk.pool.return('game/prefab/coin', target);
- if (end_node) {
- cc.tween(end_node).to(0.1, { scale: 1.2 }).to(0.05, { scale: 1 }).start();
- }
- if (item_cb != null) {
- this.is_new_cb && item_cb();
- this.is_new_cb = false;
- }
- this.iconScale(type);
- })
- .start();
- }
- /**
- * icon缩放动画
- * @param type icon类型
- * @returns
- */
- private iconScale(type: number) {
- let node;
- if (type === 1) {
- node = gData.gameData.gameStyle.icon_hb;
- } else if (type === 3) {
- node = gData.gameData.gameStyle.icon_zb;
- }
- if (!node) return;
- let scale1 = cc.tween().to(0.05, { scale: 0.9 });
- let scale2 = cc.tween().to(0.05, { scale: 1 });
- let seque = cc.tween().sequence(scale1, scale2);
- cc.tween(node).then(seque).repeat(2).start();
- }
- }
|