Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. --
  2. function create_button(btn_num)
  3. return
  4. {
  5. --上次按压后的时间
  6. time_since_press=100,
  7. --按键按下去的持续时间
  8. time_held=0,
  9. --按钮
  10. button_number=btn_num,
  11.  
  12. button_init=function(b)
  13. b.time_since_press,b.time_held=100,0
  14. end,
  15.  
  16. button_update=function(b)
  17. b.time_since_press+=one_frame
  18. --当按键按下时开始记录按下持续时间和上次按下持续时间
  19. if btn(b.button_number) then
  20. if b.time_held==0 then
  21. b.time_since_press=0
  22. end
  23.  
  24. b.time_held+=one_frame
  25. else
  26. b.time_held=0
  27. end
  28. end,
  29.  
  30. --重新初始化按钮
  31. button_consume=function(b)
  32. b.time_since_press=100
  33. end,
  34. }
  35. end
  36.  
  37. --
  38.  
  39. shoot_button=create_button(4)
  40. dash_button=create_button(5)
  41. shoot_button:button_init()
  42. dash_button:button_init()
  43.  
  44. --如果按键按下去的时间不足0.2s,则将按钮的time_since_press设为100,即使按钮还没有抬起,依旧不会执行if中的语句,当再次按下按钮的时候time_since_press会被重置为0并触发if语句
  45. if shoot_button.time_since_press<.2 or dash_button.time_since_press<.2 then
  46. shoot_button:button_consume()
  47. dash_button:button_consume()
  48. end
  49.  
  50. --在_update中执行button_update
  51. shoot_button:button_update()
  52. dash_button:button_update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement