UIGameJoystick.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. import { _decorator, Component, KeyCode, Node } from 'cc';
  2. import { GameUILayers } from '../../scripts/GameUILayers';
  3. import { Layout_UIGameJoystick } from './Layout_UIGameJoystick';
  4. import { GameMgr, Skill } from '../../module_basic/scripts/GameMgr';
  5. import { ModuleDef } from '../../scripts/ModuleDef';
  6. const activeSkillIds = [Skill.SKILL_1, Skill.SKILL_2];
  7. @tgx_class(ModuleDef.GAME)
  8. export class UIGameJoystick extends tgx.UIController {
  9. constructor(){
  10. super('ui_game_joystick/ui_game_joystick',GameUILayers.JOY_STICK,Layout_UIGameJoystick);
  11. }
  12. protected onCreated(): void {
  13. tgx.UIJoystick.inst.cleanKeyMap();
  14. tgx.UIJoystick.inst.bindKeyToButton(KeyCode.KEY_J, 'btn_skill_1');
  15. tgx.UIJoystick.inst.bindKeyToButton(KeyCode.KEY_K, 'btn_skill_2');
  16. tgx.UIJoystick.inst.bindKeyToButton(KeyCode.KEY_L, 'btn_spawn');
  17. }
  18. protected onUpdate(dt: number): void {
  19. let layout = this._layout as Layout_UIGameJoystick;
  20. activeSkillIds.forEach((skillId) => {
  21. let cdPercent = 0;
  22. let cdInfo = GameMgr.inst.getSkillCd(skillId);
  23. if (cdInfo) {
  24. cdPercent = cdInfo.cdPercent;
  25. }
  26. layout.cdSprites[skillId - Skill.SKILL_1].fillRange = cdPercent;
  27. });
  28. }
  29. }