Page 7 of 15
Re: HUMP - yet another set of helpers
Posted: Sat Feb 18, 2012 3:00 pm
by MarekkPie
Yeah, my bad.
Re: HUMP - yet another set of helpers
Posted: Thu Apr 26, 2012 11:20 am
by mofr
Very nice and compact lib, vdrl, thank you!
What do you think about multiple timer instances in one game?
For example, one timer for one game state.
Something like this:
Code: Select all
-- load library
hump_timer = require 'hump.timer'
-- create timer instance with separate update, add, addPeriodic etc functions
timer1 = hump_timer.new()
-- another instance
timer2 = hump_timer.new()
-- timer1:add(1, function() end )
-- timer2:add(1, function() end )
-- timer1:update(dt)
-- timer2:update(dt)
-- etc
Re: HUMP - yet another set of helpers
Posted: Fri Apr 27, 2012 3:34 pm
by vrld
I've given that some thought but went with a single instance timer because of two reasons:
- It's a more compact implementation, and more importantly
- It's an easier, more direct interface.
I don't really see the benefit of having timer instances, but am willing to implement it if there is reason that outweighs having a simple interface.One timer per gamestate is (imo) no such reason: To avoid timers to "leak" from the previous to the current state, you tend to clear all timers (Timer.clear) anyway when switching state.
Re: HUMP - yet another set of helpers
Posted: Sat Apr 28, 2012 7:07 am
by mofr
The main reason is possibility to pause a group of timers.
Example. There are two states: game process and menu. When user enters menu I have to pause game timers (to allow user continue game and its timers) and run menu timers. When user resumes a game I have to pause menu timers and continue updating only playgame-state timers.
P.S. sorry for my english.
Re: HUMP - yet another set of helpers
Posted: Tue May 08, 2012 3:39 am
by mofr
Example 2. Arkanoid. Level finished and I add a timer function with level changing code. Then I press escape to enter menu and pause the game, but no way to pause my timer function with level transition.
Whether correctly I use the hump timer library?
Re: HUMP - yet another set of helpers
Posted: Tue May 08, 2012 11:36 am
by vrld
That are some compelling points. However, I am still not fully convinced to drop the simple interface (maybe we can have a hybrid approach though). Can you give an example of timers you need to run during the pause menu, but not during the game?
Re: HUMP - yet another set of helpers
Posted: Tue May 08, 2012 3:01 pm
by mofr
vrld wrote:Can you give an example of timers you need to run during the pause menu, but not during the game?
There are various delayed and periodical animations and events, which I want to add to my menu (not only menu gamestate).
Concrete examples:
- After "resume game" click, we run menu dissappearance animation (or another transition effect) and only then (1 sec, for example) continue the game;
- Run some demo when user wait for long enough (remember mortal combat).
There are two little (imo) differencies between current simple interface and complicated:
1. Minimal library initialization requires two lines of code
versus complicated
Code: Select all
hump_timer = require 'hump.timer'
timer = hump_timer()
2. Methods versus library functions:
versus complicated
Re: HUMP - yet another set of helpers
Posted: Tue May 08, 2012 3:35 pm
by vrld
You convinced me.
You can now create individual timers:
Code: Select all
local Timer = require 'hump.timer'
function love.load()
foo = Timer.new()
bar = Timer()
foo:addPeriodic(5, function()
print('foo')
bar:add(1, function() print('bar') end)
end)
end
function love.update(dt)
foo:update(dt)
bar:update(dt/2)
end
For the sake of simplicity, there is a global/default timer, which you can access just like before, i.e.
Code: Select all
Timer.add(1, function() print('baz') end
Note that timer objects use the
: syntax, while the default timer uses the
. as before.
Re: HUMP - yet another set of helpers
Posted: Tue May 08, 2012 3:56 pm
by mofr
Many thanks, vrld!
Default/global timer is very good idea. Backward compatibility and simple interface are preserved.
Re: HUMP - yet another set of helpers
Posted: Tue May 08, 2012 10:47 pm
by summered
I'm now using the gamestate lib, and it is amazingly simple to use.
Thanks a lot for building and releasing it.