(animated-sprite sprite-group
pos
size
spritesheet-texture-key
spritesheet-size
&
{:keys [rotation vel update-fn draw-fn points bounds-fn offsets
animations current-animation debug? debug-color extra]
:or {vel [0 0]
offsets [:center]
current-animation :none
draw-fn draw-animated-sprite!
animations {:none
{:frames 1 :y-offset 0 :frame-delay 100}}
rotation 0
debug-color p/red
extra {}
update-fn update-animated-sprite
debug? false}})
(capture-gl-state)
Capture the current blending state of GL so we can draw NanoVG text (which blats the config) before restoring the original state for drawing images/shapes.
Capture the current blending state of GL so we can draw NanoVG text (which blats the config) before restoring the original state for drawing images/shapes.
(default-bounding-poly {[w h] :size})
Generates a bounding polygon based on the :size
rectangle of a
sprite.
Generates a bounding polygon based on the `:size` rectangle of a sprite.
(draw-animated-sprite! {:keys [pos spritesheet-texture spritesheet-size
current-animation animation-frame rotation]
[w h :as size] :size
:as s})
(draw-default-sprite! {:keys [pos size color] :as s})
Draw a green square as a sprite placeholder.
Draw a green square as a sprite placeholder.
(draw-scene-sprites! {:keys [current-scene] global-debug? :debug? :as state})
Draw each sprite in the current scene using its :draw-fn
.
Draw each sprite in the current scene using its `:draw-fn`.
(draw-text-sprite! {:keys [window vg vg-color default-font] :as state}
{:keys [pos content font font-size color rotation] :as s})
(has-group sprite-group)
Creates a predicate function for filtering sprites based on their
:sprite-group.
Takes either a single :sprite-group
keyword, or a collection of
them.
Commonly used alongside update-sprites
:
(sprite/update-sprites state (sprite/has-group :asteroids) sprite-update-fn)
(sprite/update-sprites state (sprite/has-group [:asteroids :ships]) sprite-update-fn)
Creates a predicate function for filtering sprites based on their `:sprite-group.` Takes either a single `:sprite-group` keyword, or a collection of them. Commonly used alongside `update-sprites`: (sprite/update-sprites state (sprite/has-group :asteroids) sprite-update-fn) (sprite/update-sprites state (sprite/has-group [:asteroids :ships]) sprite-update-fn)
(image-sprite sprite-group
pos
size
image-texture-key
&
{:keys [rotation vel update-fn draw-fn points bounds-fn offsets
debug? debug-color extra]
:or {rotation 0
vel [0 0]
update-fn update-pos
draw-fn draw-image-sprite!
offsets [:center]
debug? false
debug-color p/red
extra {}}})
(pos-offsets {[x-off y-off] :offsets [w h] :size})
Determine the x and y offsets for a sprite based on it's :w
, :h
and :offsets
configuration.
Defaults to [:center :center]
.
Determine the x and y offsets for a sprite based on it's `:w`, `:h` and `:offsets` configuration. Defaults to `[:center :center]`.
(restore-gl-state {:keys [src-rgb src-alpha dst-rgb dst-alpha blend-enabled?]})
Restore the original blending state of GL for drawing images/shapes.
Restore the original blending state of GL for drawing images/shapes.
(sprite sprite-group
pos
&
{:keys [size vel color update-fn draw-fn points bounds-fn offsets debug?
debug-color extra]
:or {vel [0 0]
offsets [:center]
draw-fn draw-default-sprite!
color p/white
debug-color p/red
extra {}
size [20 20]
update-fn update-pos
debug? false}})
The simplest sensible sprite.
Takes a sprite-group
(a label for sprites of this type) and a
pos
(an [x y]
position vector).
Can be enriched with any custom fields by providing an :extra
kwarg map.
The simplest sensible sprite. Takes a `sprite-group` (a label for sprites of this type) and a `pos` (an `[x y]` position vector). Can be enriched with any custom fields by providing an `:extra` kwarg map.
(text-sprite sprite-group
pos
content
&
{:keys [rotation vel update-fn draw-fn points bounds-fn offsets
font font-size color debug? debug-color extra]
:or {vel [0 0]
offsets [:left :bottom]
draw-fn draw-text-sprite!
rotation 0
color p/white
font-size 32
debug-color p/red
font "sans"
update-fn identity
debug? false}})
(update-animated-sprite s)
Update the animation of a sprite in addition to it's position.
Update the animation of a sprite in addition to it's position.
(update-animation {:keys [current-animation delay-count] :as s})
If the :delay-count
is zero, move to the next animation frame.
If the `:delay-count` is zero, move to the next animation frame.
(update-frame-delay {:keys [current-animation] :as s})
Increment the :delay-count
(wrapping to zero at :frame-delay
).
The animation frame will change at 0.
Increment the `:delay-count` (wrapping to zero at `:frame-delay`). The animation frame will change at 0.
(update-pos {[x y] :pos [vx vy] :vel :as s})
Update the sprite position based on its velocity.
Update the sprite position based on its velocity.
(update-sprites state f)
(update-sprites {:keys [current-scene] :as state} pred f)
Update sprites in the current scene with the update function f
.
Optionally takes a filtering function pred
.
Update sprites in the current scene with the update function `f`. Optionally takes a filtering function `pred`.
(update-state {:keys [current-scene] :as state})
Update each sprite in the current scene using its :update-fn
.
Update each sprite in the current scene using its `:update-fn`.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close