CoinsAction.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { _decorator, Component, easing, instantiate, Label, Node, tween, UITransform, Vec3 } from 'cc';
  2. import { PoolMgr } from './PoolMagr';
  3. import { Global } from './Global';
  4. import { Clips } from './Enums';
  5. import { AudioMgr } from './AudioMgr';
  6. import { Tools } from './Tools';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('CoinsAction')
  9. export class CoinsAction extends Component {
  10. @property({type:Label})
  11. level_label:Label = null;
  12. start() {
  13. this.refrush_coins();
  14. }
  15. update(deltaTime: number) {
  16. }
  17. refrush_coins(){
  18. this.level_label.string = Global.cur_coins+"";
  19. }
  20. put_coins(num:number,world_pos:Vec3,play_sound:boolean = true){
  21. //记录
  22. Global.cur_coins = Global.cur_coins+num;
  23. let prefab = PoolMgr.ins.getPrefab("coin");
  24. for(let i =0;i<num;i++){
  25. let coin = instantiate(prefab);
  26. let local = this.node.getComponent(UITransform).convertToNodeSpaceAR(world_pos);
  27. this.node.addChild(coin);
  28. local.x = local.x + Tools.random_between(-30,80);
  29. local.y = local.y + Tools.random_between(0,150);
  30. coin.setPosition(local);
  31. let show = false;
  32. if(num-1 == i){
  33. show = true;
  34. }
  35. tween(coin)
  36. .to(Tools.random_between(0.5,1.5),{position:new Vec3(0,0,0)},Global.our_easing)
  37. .call(()=>{
  38. if(show){
  39. this.refrush_coins();
  40. }
  41. if(Global.cur_coins>0 && play_sound){
  42. AudioMgr.ins.playSound(Clips.coins);
  43. }
  44. })
  45. .removeSelf()
  46. .start();
  47. }
  48. }
  49. }
  50. //电子邮件puhalskijsemen@gmail.com
  51. //源码网站 开vpn打开 http://web3incubators.com/
  52. //电报https://t.me/gamecode999