Sprites, for drawing and animating game objects.
The basic sprites provided are useful if simple, feel free to implement your own.
Sprites, for drawing and animating game objects. The basic sprites provided are useful if simple, feel free to implement your own.
(animated-sprite sprite-group
pos
w
h
spritesheet-file
&
{:keys [rotation vel update-fn draw-fn animations
current-animation points bounds-fn offsets extra]
:or {rotation 0
vel [0 0]
update-fn update-animated-sprite
draw-fn draw-animated-sprite!
animations {:none
{:frames 1 :y-offset 0 :frame-delay 100}}
current-animation :none
offsets [:center]
extra {}}})
(default-bounding-poly {:keys [w h]})
Generates a bounding polygon based off the w
by h
rectangle of
the sprite.
Generates a bounding polygon based off the `w` by `h` rectangle of the sprite.
(draw-animated-sprite! {:keys [pos rotation w h spritesheet current-animation
animation-frame]
:as s})
(draw-scene-sprites! {:keys [current-scene] :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-scene-sprites-by-layers! {:keys [current-scene] :as state} layers)
Draw each sprite in the current scene using its :draw-fn
in the
order their :sprite-group
appears in the layers
list.
Any sprites with groups not found in layers
will be drawn last.
Draw each sprite in the current scene using its `:draw-fn` in the order their `:sprite-group` appears in the `layers` list. Any sprites with groups not found in `layers` will be drawn last.
(has-group sprite-group)
Creates a predicate function that filters sprites based on their
:sprite-group.
Takes either a single :sprite-group
keyword, or a collection of
them.
Commonly used alongside update-sprites-by-pred
:
(sprite/update-sprites-by-pred state (sprite/has-group :asteroids) sprite-update-fn)
(sprite/update-sprites-by-pred state (sprite/has-group [:asteroids :ships]) sprite-update-fn)
Creates a predicate function that filters sprites based on their `:sprite-group.` Takes either a single `:sprite-group` keyword, or a collection of them. Commonly used alongside `update-sprites-by-pred`: (sprite/update-sprites-by-pred state (sprite/has-group :asteroids) sprite-update-fn) (sprite/update-sprites-by-pred state (sprite/has-group [:asteroids :ships]) sprite-update-fn)
(image-sprite sprite-group
pos
w
h
image-file
&
{:keys [rotation vel update-fn draw-fn points bounds-fn offsets
extra]
:or {rotation 0
vel [0 0]
update-fn update-pos
draw-fn draw-image-sprite!
offsets [:center]
extra {}}})
(pos-offsets {[x-off y-off] :offsets :keys [w h]})
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]`.
(sprite sprite-group
pos
&
{:keys [w h vel update-fn draw-fn points bounds-fn offsets extra]
:or {w 20
h 20
vel [0 0]
update-fn update-pos
draw-fn draw-default!
offsets [:center]
extra {}}})
The simplest sensible sprite.
Contains a position, velocity, dimensions for collision detection,
can be enriched with any custom fields via the :extra
kwarg.
The simplest sensible sprite. Contains a position, velocity, dimensions for collision detection, can be enriched with any custom fields via the `:extra` kwarg.
(text-sprite content
pos
&
{:keys [offsets sprite-group font size color update-fn draw-fn
extra]
:or {offsets [:center]
sprite-group :text
font u/default-font
size u/default-text-size
color u/black
update-fn identity
draw-fn draw-text-sprite
extra {}}})
(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