diff options
| author | Amir Rajan <[email protected]> | 2020-08-06 08:12:27 -0500 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2020-08-06 08:12:27 -0500 |
| commit | 64046616ce54fff32c3dd949a4b7702136f38a3e (patch) | |
| tree | 1fff22cf553b2cf3eb5fe8095b572fd0cce63196 /docs/search_results.txt | |
| parent | 161d498dc905f04b595c927309993acdcb4d394c (diff) | |
| download | dragonruby-game-toolkit-contrib-64046616ce54fff32c3dd949a4b7702136f38a3e.tar.gz dragonruby-game-toolkit-contrib-64046616ce54fff32c3dd949a4b7702136f38a3e.zip | |
Synced with 1.14
Diffstat (limited to 'docs/search_results.txt')
| -rw-r--r-- | docs/search_results.txt | 104 |
1 files changed, 56 insertions, 48 deletions
diff --git a/docs/search_results.txt b/docs/search_results.txt index b4c5e12..50311a3 100644 --- a/docs/search_results.txt +++ b/docs/search_results.txt @@ -1,63 +1,71 @@ -* DOCS: ~Numeric#frame_index~ +* DOCS: ~Numeric#elapsed_time~ +For a given number, the elapsed frames since that number is returned. +`Kernel.tick_count` is used to determine how many frames have elapsed. +An optional numeric argument can be passed in which will be used instead +of `Kernel.tick_count`. -This function is helpful for determining the index of frame-by-frame - sprite animation. The numeric value ~self~ represents the moment the - animation started. +Here is an example of how elapsed_time can be used. -~frame_index~ takes three additional parameters: +#+begin_src ruby + def tick args + args.state.last_click_at ||= 0 -- How many frames exist in the sprite animation. -- How long to hold each animation for. -- Whether the animation should repeat. + # record when a mouse click occurs + if args.inputs.mouse.click + args.state.last_click_at = args.state.tick_count + end -~frame_index~ will return ~nil~ if the time for the animation is out -of bounds of the parameter specification. + # Use Numeric#elapsed_time to determine how long it's been + if args.state.last_click_at.elapsed_time > 120 + args.outputs.labels << [10, 710, "It has been over 2 seconds since the mouse was clicked."] + end + end +#+end_src -Example using variables: +And here is an example where the override parameter is passed in: #+begin_src ruby def tick args - start_looping_at = 0 - number_of_sprites = 6 - number_of_frames_to_show_each_sprite = 4 - does_sprite_loop = true - - sprite_index = - start_looping_at.frame_index number_of_sprites, - number_of_frames_to_show_each_sprite, - does_sprite_loop - - sprite_index ||= 0 - - args.outputs.sprites << [ - 640 - 50, - 360 - 50, - 100, - 100, - "sprites/dragon-#{sprite_index}.png" - ] + args.state.last_click_at ||= 0 + + # create a state variable that tracks time at half the speed of args.state.tick_count + args.state.simulation_tick = args.state.tick_count.idiv 2 + + # record when a mouse click occurs + if args.inputs.mouse.click + args.state.last_click_at = args.state.simulation_tick + end + + # Use Numeric#elapsed_time to determine how long it's been + if (args.state.last_click_at.elapsed_time args.state.simulation_tick) > 120 + args.outputs.labels << [10, 710, "It has been over 4 seconds since the mouse was clicked."] + end end #+end_src -Example using named parameters: + +* DOCS: ~Numeric#created?~ +Returns true if ~Numeric#elapsed_time == 0~. Essentially communicating that +number is equal to the current frame. + +Example usage: #+begin_src ruby - start_looping_at = 0 - - sprite_index = - start_looping_at.frame_index count: 6, - hold_for: 4, - repeat: true - - sprite_index ||= 0 - - args.outputs.sprites << [ - 640 - 50, - 360 - 50, - 100, - 100, - "sprites/dragon-#{sprite_index}.png" - ] -#+end_src + def tick args + args.state.box_queue ||= [] + + if args.state.box_queue.empty? + args.state.box_queue << { name: :red, + create_at: args.state.tick_count + 60 } + end + boxes_to_spawn_this_frame = args.state + .box_queue + .find_all { |b| b[:create_at].new? } + + boxes_to_spawn_this_frame.each { |b| puts "box #{b} was new? on #{args.state.tick_count}." } + + args.state.box_queue -= boxes_to_spawn_this_frame + end +#+end_src |
