| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- /**
- * @description 获取道具特效
- * @author kaka
- * */
- const { ccclass } = cc._decorator;
- @ccclass
- export default class FlySystem extends cc.Component {
- onLoad() {
- mk.fly = this;
- }
- /**
- * @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, cb: Function = null) {
- for (let i = 0; i < num; i++) {
- let copyCoin = await mk.pool.getPrefab('game/prefab/coin');
- let url = 'module/icon/reward' + 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.8, 1.2, 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(copyCoin, initPos, endpos, cb);
- }
- }
- private FlyIn(target: cc.Node, end: cc.Vec2, endpos: cc.Vec2 | string = null, cb: Function = null) {
- cc.tween(target)
- .to(mk.math.random(0.3, 0.6, false), { position: cc.v3(end) }, cc.easeSineInOut())
- .call(() => {
- this.FlyOut(target, endpos, cb);
- })
- .start();
- }
- private FlyOut(target: cc.Node, end: cc.Vec2 | string, 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') {
- 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 = end as cc.Vec2;
- }
- 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 (cb != null) {
- cb();
- }
- })
- .start();
- }
- }
|