NodeUtils.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {_decorator, Component, Node, tween, UITransform, v3} from 'cc';
  2. const {ccclass, property} = _decorator;
  3. @ccclass('NodeUtils')
  4. export class NodeUtils extends Component {
  5. /**
  6. * 物品冒泡出现
  7. * @param n
  8. */
  9. public static maoPaoShow(n: Node, callback: Function = null, time: number = 0.3) {
  10. n.active = true
  11. const orignSize = n.getComponent(UITransform).contentSize
  12. n.scale = v3(0, 0, 1)
  13. tween(n).to(time, {scale: v3(1, 1, 1)}, {easing: "backOut"})
  14. .call(() => {
  15. n.getComponent(UITransform).setContentSize(orignSize)
  16. if (null != callback) {
  17. callback()
  18. }
  19. })
  20. .start()
  21. }
  22. /**
  23. * 翻牌效果
  24. * @param n
  25. * @param callback
  26. * @param time
  27. */
  28. public static pokeChange(n: Node, callback: Function = null, time: number = 0.2) {
  29. n.getChildByName("back").scale = v3(0, 1)
  30. n.getChildByName("back").active = true
  31. tween(n.getChildByName("font")).to(time, {scale: v3(0, 1)})
  32. .call(() => {
  33. n.getChildByName("font").active = false
  34. tween(n.getChildByName("back")).to(time, {scale: v3(1, 1)}).start()
  35. })
  36. .start()
  37. }
  38. public static shakeNode(n: Node, callback: Function = null, time: number = 0.2) {
  39. const pos = n.getPosition()
  40. tween(n).to(time, {position: v3(pos.x - 50, pos.y)})
  41. .call(() => {
  42. tween(n).to(time, {position: v3(pos)}, {easing: "backOut"})
  43. .call(() => {
  44. if (null != callback) {
  45. callback()
  46. }
  47. })
  48. .start()
  49. })
  50. .start()
  51. }
  52. }