Simplifier.gml 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /// @desc 优雅地在给定深度与位置创建某个实例
  2. /// @param {Asset.GMObject} _obj 将要创建的实例
  3. /// @param {real} _x x坐标,默认为创建者的x坐标
  4. /// @param {real} _y y坐标,默认为创建者的y坐标
  5. /// @param {real} _depth 深度,默认为0
  6. function icd(_obj, _x = x, _y = y, _depth = 0)
  7. {
  8. return instance_create_depth(_x, _y, _depth, _obj);
  9. }
  10. /// @desc 优雅地在给定层级与位置创建某个实例
  11. /// @param {Asset.GMObject} _obj 将要创建的实例
  12. /// @param {real} _x x坐标,默认为创建者的x坐标
  13. /// @param {real} _y y坐标,默认为创建者的y坐标
  14. /// @param {string} _layer_id 层级,默认为"Instances"
  15. function icl(_obj, _x = x, _y = y, _layer_id = "Instances")
  16. {
  17. return instance_create_layer(_x, _y, _layer_id, _obj);
  18. }
  19. /// @desc 内部辅助函数,自动检测字符类型并映射为整数(不要在外部直接调用)
  20. /// @param {Constant.VirtualKey|Real} _key 需要转义的字符
  21. function key_get_id(_key) {
  22. return is_string(_key) ? ord(_key) : _key;
  23. }
  24. /// @desc 优雅地检测此帧某给定键盘按键是否被按住
  25. /// @param {Constant.VirtualKey|Real} _key 检测的键盘按键
  26. function kc(_key)
  27. {
  28. return keyboard_check(key_get_id(_key));
  29. }
  30. /// @desc 优雅地检测此帧某给定键盘按键是否被按下
  31. /// @param {Constant.VirtualKey|Real} _key 检测的键盘按键
  32. function kcp(_key) {
  33. return keyboard_check_pressed(key_get_id(_key));
  34. }
  35. /// @desc 优雅地检测此帧某给定键盘按键是否被松开
  36. /// @param {Constant.VirtualKey|Real} _key 检测的键盘按键
  37. function kcr(_key) {
  38. return keyboard_check_released(key_get_id(_key));
  39. }