Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Framerate Limits?
- By ? Date 2009-02-03 02:10
I'm working on a smooth scrolling tile engine (a la early console RPGs).  So far, I'm really liking Gosu.  I had tried a lua engine and a few other ruby engines, but Gosu seems to be the most comfortable.  However, being very new to graphics programming in general, I'm having trouble figuring out how to resolve one problem with moving my player around.  Since I can't tell how to set a target FPS, I have my guy moving 32px--one tile--on each button down of an arrow key.  He moves at lightspeed, leaping multiple tiles in a single depression.  Can I slow him down in any way other than by reducing the number of pixels he moves in "one" down event?

Thanks in advance!
- By philomory Date 2009-02-03 03:17
Personally, I have this code in my Player class... obviously you would need to tailor it to your own game somewhat.

def initialize(...)
  ...
  @movement_delay = 0.2
  ...
end

def pressedMovementKey(direction)
  return if Time.now - @last_moved < @movement_delay
  if @facing == direction then
    destination = self.send(direction)
    if destination.empty? || destination.collectible? || destination.pushed(direction) then #Short-circuit evaluation is relied on here
      @y -= 1 if direction == :north
      @y += 1 if direction == :south
      @x += 1 if direction == :east
      @x -= 1 if direction == :west
      destination.playerEnteredTile(self)
    else
     puts "Bump!"
    end
  else
    @facing = direction
  end
  @last_moved = Time.now
end
- By jlnr (dev) Date 2009-02-03 09:21
I usually set a counter when I'm moving and decrease it every frame (= update call). If it's 0, the object is allowed to move again.

You can actually set the target FPS via the last argument to Window#initialize, which is defaulted to 16.6666667 and specifies the millisecond duration between update calls. But if you set it to something really large, i.e. one second, hitting escape to quit the game might also take a second to happen, and the game will seem unresponsive. (I'd always go with the default value.)
- By ? Date 2009-02-03 18:07
Thanks for the help!  I adjusted my tile movement size to a fraction of the tile size and that is working for now.  I'm ironing out some issues with borders as the map scrolls and it's scrolling kind of jerky, but I'm making good progress for never having done this before and going off C tutorials from '99.  I will come back and use your suggestions to time out movement better once I get the map stuff working correctly.
Up Topic Gosu / Gosu Exchange / Framerate Limits?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill