Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Any way to slow down Input.repeat?

I changed my frame rate to 60, but now the Input.repeat? method moves the cursor too frequently. Is there any way to remedy this? Thanks in advance.
 

Zeriab

Sponsor

There are several ways to remedy it.
How do you want to slow it down? Do you want to have it the same speed as when the frame rate was 40?
Do you want it normalized so that the speed stays the same (or as same as possible) regardless of the frame rate?
 

Zeriab

Sponsor

Just copy and paste this script into a new section anywhere above Main.
You can change numbers in REPEAT_WAIT = 6 and REPEAT_START_WAIT = 24 to alter the speed of the repeat.

[rgss]module Input
  # Frames to wait between each repeat
  REPEAT_WAIT = 6
  # Frames to wait from the first repeat to the following repeats
  REPEAT_START_WAIT = 24
 
  KEYS = [DOWN, LEFT, RIGHT, UP,
          A, B, C, X, Y, Z, L, R,
          SHIFT, CTRL, ALT,
          F5, F6, F7, F8, F9]
 
  class << self
    unless method_defined?:)zeriab_repeat_change_update)
      alias zeriab_repeat_change_update update
    end
    def update
      zeriab_repeat_change_update
      # Create button state hash if needed
      if @button_states.nil?
        @button_states = {}
        for key in KEYS
          @button_states[key] = 0
        end
      end
      # Check for press
      for key in KEYS
        if press?(key)
          @button_states[key] += 1
        else
          @button_states[key] = 0
        end
      end
    end
   
    def repeat?(id)
      if @button_states[id] <= 0
        return false
      elsif @button_states[id] == 1
        return true
      elsif @button_states[id] > REPEAT_START_WAIT
        return @button_states[id] % REPEAT_WAIT == 1
      end
    end
  end
end
[/rgss]

*hugs*
- Zeriab
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top