sprite2dplugin
Rows drawn as frames of a sprite sheet in render2d's world.
Putting it in a scene
List it before render2d. Every row of a kind in kinds is drawn as a frame of a sprite sheet standing on the row's pos.
"plugins": ["loader", "scenemanager", "player", "sprite2d", "render2d"],
"world": {
"render2d": { "ground": [[1, 0], [0, 1]], "up": [0, -1], "zoom": 2, "look": [0, 0], "layers": ["ground", { "name": "things", "sort": true }] },
"sprite2d": {
"kinds": {
"fighter": { "layer": "things", "turn": 8, "shadow": { "layer": "ground", "size": [10, 5], "alpha": 0.4, "fade": 0.1 } },
"coin": { "layer": "things", "turn": 1, "sheet": "coins", "clip": "spin", "facing": 0 }
}
}
}
A row of the fighter kind:
{ "sheet": "fighter", "clip": "idle", "frame": 0, "facing": 2, "pos": [120, 80] }
Properties
Read from world.sprite2d.kinds.<kind>. A kind's rules can read the same entry.
.layer : string
The render2d layer the sprites are drawn on. On a layer with sort: true, sprites are drawn in order of the depth of the ground under them, so a jump doesn't change what a sprite stands in front of. Of two sprites at one depth, the kind listed later in the table is drawn on top.
.turn : number
How many facings make a whole turn. A row's facing × a whole turn ÷ turn is the direction it heads, counter-clockwise from the world's x toward its −y.
.sheet, .clip, .facing
Optional. For a kind whose rows all look the same way, such as a coin, any of these can be given once here instead of on every row. A row that also carries a field given here is an error.
.shadow : { layer, size?, clip?, alpha, fade }
A shadow under each sprite on the render2d layer layer. It is an ellipse reaching size [across, down] stage pixels out from the ground under the sprite, so twice that wide and high, in black at opacity alpha. The opacity falls by fade for every step of height the sprite stands above the ground, down to none. With clip the shadow is that clip's silhouette instead, turning as the sprite turns, and size is not used.
The row
Fields of a row of a listed kind.
| Field | Meaning |
|---|---|
sheet | The loader name of the sprite sheet. |
clip | The clip of the sheet to play. |
frame | The frame of the clip shown. A row whose rule advances it should use play from the loader. Left out, the first frame shows. |
facing | Which way it heads, as above. The sprite shows the run of the sheet that faces nearest the way the heading is drawn on screen. A run the sheet mirrors is drawn flipped about the frame's anchor. |
pos | [x, y] on the ground or [x, y, h] at height h. The frame's anchor stands on it. |
shadow | A number the shadow's opacity is multiplied by. 0 casts none. |
alpha | Opacity from 0 to 1, default 1. |
flip | True to draw it upside down in its frame's own place, such as something knocked over. |
palette | The loader name of a palette entry to draw it in. Colour k of the palette named in the sheet's catalogue entry becomes colour k of this one. Up to 32 colours are swapped, and only pixels of exactly that colour. Left out or null draws the sheet as it is. |
layer | A render2d layer to draw on instead of the kind's, such as for something that passes behind the ground. |
rot | [cos, sin], the direction the sprite's own x axis points, as box2d writes a body's rotation. The sprite turns about its anchor to match. The shadow does not turn. |
A sprite stays hidden, and its sheet is requested, until the loader has the sheet.