chickadee » doodle » define-resource

define-resource name type filename #!rest dataprocedure

Registers a resource under the name name. The resource is read from a file specified with filename. The type argument is a keyword and specifies how the data argument is handled and which form is expected.

The following types are handled:

* #:image

A single image from a single file. It takes optional argumens x-offset, y-offset and scale-factor to take just a fraction out of the given image file and to be able to scale it.

The following example does this several times:

(define-resource 'water #:image "Water Block.png" *terrain-xoffset* *terrain-yoffset*)
(define-resource 'stone #:image "Stone Block.png" *terrain-xoffset* *terrain-yoffset*)
(define-resource 'princess #:image "Character Princess Girl.png" 0 -80)
(define-resource 'bubble #:image "SpeechBubble.png" -15 -120)
(define-resource 'bug #:image "Enemy Bug.png" 0 -80)
(define-resource 'tree #:image "Tree Tall.png" 0 -80 )
(define-resource 'heart #:image "Heart.png" 0 0 0.5)
* #:tileset

This assumes the image to consist of one or more square tiles. Then several images are referenced out of a single image file. The data argument is expected to be a list of two elements: the tile-size and a list consisting of (name number) pairs (proper lists). The following examples makes three tiles accessible through their names: wall, floor and hero. They can be drawn with the blit-image procedure.

(define-resource 'tiles
                    '((wall 2)
                      (floor 30)
                      (hero 486)))