Skip to contents

Calls render.sprite() using an object's $spritename (the name of the desired sprite in RAM$ROM$sprites).

The object is drawn at position (obj$x, obj$y) on layer obj$layer if specified (see below).

Objects with no $spritename will not be drawn, unless they have custom drawing behavior defined in obj$draw():

If the object has a function set for obj$draw(), it will be run instead of render.sprite(). This allows the game dev to create custom drawing behavior.

scene = obj$draw(scene, obj, RAM)

Usage

render.object(scene, obj, RAM)

Arguments

scene

Scene object.

obj

Object in RAM$objects. Objects with a $spritename will be drawn.

RAM

RAM object.

Value

Returns the scene object with sprite drawn. This function is called by render.ram() for each object in RAM$objects.

Details

An object only needs a $spritename to be drawn. Objects can also have the following properties which influence how they're drawn: otherwise, the default value (second column) will be used.

$spritenameName of sprite in ROM$sprites.
$x 1X-coordinate at which to draw the object's sprite in the scene.
$y1Y-coordinate.
$offset.x0Pixels to offset sprite horizontally from obj$x.
$offset.y0Vertical offset.
$layer2Layer on which to draw the sprite. See render.scene; high layers are drawn on top.
$timerRAM$timer Tick count (ascending) for animations.
$paletteNULLVector to swap the colors of the object's sprite around, e.g. c(0,2,1) swaps values of 2 and 1. Index starts at 0. Defaults to no swapping.
$draw()NULLOverwrites the default drawing behavior for the sprite; see above.

Offsets

Both the obj and sprite can have optional offset.x/offset.y properties to offset the draw location of their sprite from their position. This can be useful for animation and aligning an object's sprite with its actual hitbox.

If both object and sprite have an offset property, the two are added.

Examples

smileysprite = matrix(c(0,0,1,0,0,0,0,1,1,1,0,1,0,0,0,1,1,1,0,1,0,0,0,1,0,0,1,0), ncol = 7)
RAM = ram.init(rom.init(16,8,sprites=list(smiley=smileysprite)))
RAM$objects$smiley = list(x = 3, y = 3, spritename = 'smiley')
scene = list(width=16,height=8)
scene = render.object(scene,RAM$objects$smiley,RAM)
render.scene(scene)
#>                                 
#>                                 
#>         []  []                  
#>         []  []                  
#>     []          []              
#>       [][][][][]                
#>                                 
#>