HUMP - yet another set of helpers
Re: HUMP - yet another set of helpers
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:
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
Sorry for my english and lua. Please, correct my mistakes!
Re: HUMP - yet another set of helpers
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.
Re: HUMP - yet another set of helpers
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.
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.
Sorry for my english and lua. Please, correct my mistakes!
Re: HUMP - yet another set of helpers
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?
Whether correctly I use the hump timer library?
Sorry for my english and lua. Please, correct my mistakes!
Re: HUMP - yet another set of helpers
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
There are various delayed and periodical animations and events, which I want to add to my menu (not only menu gamestate).vrld wrote:Can you give an example of timers you need to run during the pause menu, but not during the game?
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).
1. Minimal library initialization requires two lines of code
Code: Select all
timer = require 'hump.timer'
Code: Select all
hump_timer = require 'hump.timer'
timer = hump_timer()
Code: Select all
timer.update(dt)
Code: Select all
timer:update(dt)
Sorry for my english and lua. Please, correct my mistakes!
Re: HUMP - yet another set of helpers
You convinced me.
You can now create individual timers:
For the sake of simplicity, there is a global/default timer, which you can access just like before, i.e.
Note that timer objects use the : syntax, while the default timer uses the . as before.
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
Code: Select all
Timer.add(1, function() print('baz') end
Re: HUMP - yet another set of helpers
Many thanks, vrld!
Default/global timer is very good idea. Backward compatibility and simple interface are preserved.
Default/global timer is very good idea. Backward compatibility and simple interface are preserved.
Sorry for my english and lua. Please, correct my mistakes!
Re: HUMP - yet another set of helpers
I'm now using the gamestate lib, and it is amazingly simple to use.
Thanks a lot for building and releasing it.
Thanks a lot for building and releasing it.
Who is online
Users browsing this forum: No registered users and 0 guests