UIGameJoystick.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132
  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. }
  17. protected onUpdate(dt: number): void {
  18. let layout = this._layout as Layout_UIGameJoystick;
  19. activeSkillIds.forEach((skillId) => {
  20. let cdPercent = 0;
  21. let cdInfo = GameMgr.inst.getSkillCd(skillId);
  22. if (cdInfo) {
  23. cdPercent = cdInfo.cdPercent;
  24. }
  25. layout.cdSprites[skillId - Skill.SKILL_1].fillRange = cdPercent;
  26. });
  27. }
  28. }