use request_animation_frame
This commit is contained in:
parent
a3093dc0c8
commit
9ad4d485a3
1 changed files with 14 additions and 7 deletions
|
|
@ -61,7 +61,7 @@ let papy_bottom = C2d.image_src_of_el (get_el "papy_bottom")
|
|||
|
||||
let water = C2d.image_src_of_el (get_el "water")
|
||||
|
||||
let draw_map () =
|
||||
let draw_map _timestamp =
|
||||
let player_x, player_y = !Map.player_pos in
|
||||
Format.printf "player_x = %d@\nplayer_y = %d@\n" player_x player_y;
|
||||
for x = 0 to tiles_per_w - 1 do
|
||||
|
|
@ -98,11 +98,18 @@ let kb_handler ev =
|
|||
let y = max 0 y in
|
||||
let y = min (Map.height - 1) y in
|
||||
Map.player_pos := (x, y);
|
||||
draw_map ()
|
||||
let _animation_frame_id = G.request_animation_frame draw_map in
|
||||
()
|
||||
|
||||
let rec game_loop _timestamp =
|
||||
(* ... update state ... *)
|
||||
draw_map ();
|
||||
ignore @@ G.request_animation_frame game_loop
|
||||
|
||||
let () =
|
||||
let on_window_load f =
|
||||
ignore @@ Ev.listen Ev.load (fun _ev -> f ()) (Window.as_target G.window)
|
||||
let on_window_load f x =
|
||||
ignore
|
||||
@@ Ev.listen Ev.load (fun _ev -> ignore @@ f x) (Window.as_target G.window)
|
||||
in
|
||||
let bind_keys () =
|
||||
ignore
|
||||
|
|
@ -110,9 +117,9 @@ let () =
|
|||
(fun ev -> kb_handler ev)
|
||||
(Window.as_target G.window)
|
||||
in
|
||||
on_window_load init_bg;
|
||||
on_window_load draw_map;
|
||||
on_window_load bind_keys
|
||||
on_window_load init_bg ();
|
||||
on_window_load bind_keys ();
|
||||
on_window_load G.request_animation_frame game_loop
|
||||
|
||||
(*
|
||||
let draw_background () =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue