import {_decorator, Component, Node, tween, UITransform, v3} from 'cc'; const {ccclass, property} = _decorator; @ccclass('NodeUtils') export class NodeUtils extends Component { /** * 物品冒泡出现 * @param n */ public static maoPaoShow(n: Node, callback: Function = null, time: number = 0.3) { n.active = true const orignSize = n.getComponent(UITransform).contentSize n.scale = v3(0, 0, 1) tween(n).to(time, {scale: v3(1, 1, 1)}, {easing: "backOut"}) .call(() => { n.getComponent(UITransform).setContentSize(orignSize) if (null != callback) { callback() } }) .start() } /** * 翻牌效果 * @param n * @param callback * @param time */ public static pokeChange(n: Node, callback: Function = null, time: number = 0.2) { n.getChildByName("back").scale = v3(0, 1) n.getChildByName("back").active = true tween(n.getChildByName("font")).to(time, {scale: v3(0, 1)}) .call(() => { n.getChildByName("font").active = false tween(n.getChildByName("back")).to(time, {scale: v3(1, 1)}).start() }) .start() } public static shakeNode(n: Node, callback: Function = null, time: number = 0.2) { const pos = n.getPosition() tween(n).to(time, {position: v3(pos.x - 50, pos.y)}) .call(() => { tween(n).to(time, {position: v3(pos)}, {easing: "backOut"}) .call(() => { if (null != callback) { callback() } }) .start() }) .start() } }