Frame delta?

8 views
Skip to first unread message

Merkoth

unread,
Jun 14, 2009, 4:02:30 PM6/14/09
to Star Ruby (English)
Hi, I'm new here and I'm just getting started with both Ruby and Star
Ruby. I was wondering if it's possible to get the delta time of each
frame, to be able to implement framerate-independent movement.
Something like this:

class Ship
def intiialize
# ...
end
def update(delta_time)
x += speed * delta_time
u += speed * delta_time
end
def draw
# ...
end
end

My best guess would be to use a timer, but I don't really understand
from the timer.rb example how to implement a custom timer. However,
since Star Ruby seems to run at a fixed framerate I wonder if this is
really necessary. Does Star Ruby only fix the drawing rate or the
entire program?

Thanks in advance!

Hajime Hoshi

unread,
Jun 16, 2009, 11:11:00 AM6/16/09
to starr...@googlegroups.com
Hi, Merkoth

I'm Hajime Hoshi, one of the Star Ruby developers.
Thank you for your using Star Ruby!

2009/6/15 Merkoth <mer...@gmail.com>


>
> Hi, I'm new here and I'm just getting started with both Ruby and Star
> Ruby. I was wondering if it's possible to get the delta time of each
> frame, to be able to implement framerate-independent movement.
> Something like this:
>
> class Ship
>  def intiialize
>    # ...
>  end
>  def update(delta_time)
>    x += speed * delta_time
>    u += speed * delta_time
>   end
>  def draw
>    # ...
>  end
> end

Please use Game.ticks method. It returns elapsed time in millisecond
from stating your program. Please let me know if this answers your
question.

> My best guess would be to use a timer, but I don't really understand
> from the timer.rb example how to implement a custom timer. However,
> since Star Ruby seems to run at a fixed framerate I wonder if this is
> really necessary. Does Star Ruby only fix the drawing rate or the
> entire program?

Star Ruby (Game.run method) fixes the entire program. timer.rb only
shows how to use some methods like Game.ticks, Game#fps, not to
implement original timers.

Thanks,

--
Hajime Hoshi <hajim...@gmail.com>

Ivan Vodopiviz

unread,
Jun 16, 2009, 12:27:06 PM6/16/09
to starr...@googlegroups.com
Hi, thanks for your reply

> Please use Game.ticks method. It returns elapsed time in millisecond
> from stating your program. Please let me know if this answers your
> question.

I was looking for the time since the last frame update, not since
starting my program but...

> Star Ruby (Game.run method) fixes the entire program. timer.rb only
> shows how to use some methods like Game.ticks, Game#fps, not to
> implement original timers.

... if it really sets a fixed execution speed, using frame deltas
isn't necessary.

Thanks for the information! :)

--
Ren | | Merkoth

Reply all
Reply to author
Forward
0 new messages