Liking cljdoc? Tell your friends :D
ClojureScript only.

minicosm.core


start!cljs

(start! {:keys [init assets] :as handlers})

Initiates the main game loop. Expects a map of handler functions with the following keys:

{:init (fn [] state) 
   A function that returns the initial game state, run before the loop starts
 :assets (fn [] assets)
   A function that returns a map of keys to asset type/url pairs, to be loaded into memory.
 :on-key (fn [state keys] state)
   A function that takes the current game state, and a set of current key codes pressed, and returns a new
   game state
 :on-tick (fn [state time] state)
   A function that takes the current game state, and a DOMHighResTimeStamp, indicating the number of ms since 
   time origin (https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp#The_time_origin).
   Runs every frame, approx. 60fps. Returns a new game state.
 :to-play (fn [state assets] sound-state)
   A function that taks the current state, assets, and a boolean indicating if music is currently playing
   and returns a map describing sounds to play, in the form:
   `{:music <sound asset to loop or :stop> :effects [<sound assets to play once>]}`. If the :music key is empty,
   any currently playing sound will continue.
 :to-draw (fn [state assets] graphics-state)
   A function that takes the current game state, and returns a DDN vector
Initiates the main game loop. Expects a map of handler functions with the following keys:
```clj
{:init (fn [] state) 
   A function that returns the initial game state, run before the loop starts
 :assets (fn [] assets)
   A function that returns a map of keys to asset type/url pairs, to be loaded into memory.
 :on-key (fn [state keys] state)
   A function that takes the current game state, and a set of current key codes pressed, and returns a new
   game state
 :on-tick (fn [state time] state)
   A function that takes the current game state, and a DOMHighResTimeStamp, indicating the number of ms since 
   time origin (https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp#The_time_origin).
   Runs every frame, approx. 60fps. Returns a new game state.
 :to-play (fn [state assets] sound-state)
   A function that taks the current state, assets, and a boolean indicating if music is currently playing
   and returns a map describing sounds to play, in the form:
   `{:music <sound asset to loop or :stop> :effects [<sound assets to play once>]}`. If the :music key is empty,
   any currently playing sound will continue.
 :to-draw (fn [state assets] graphics-state)
   A function that takes the current game state, and returns a DDN vector
```
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close