API reference

Generated from the source in apps/micropython/vs2. If you are new to VS2, read the tutorial first — this section assumes you know what a layer and a sealed scene are.

Everything lives in two modules:

vs2

Scenes, layers, drawables, and the display, audio, base and limits services.

vs2.controls

The two controllers and the button constants, designed for from vs2.controls import *.

Cheat sheet

import vs2
from vs2.controls import *

class MyGame(vs2.Scene):
    idle_timeout = 30          # seconds; None disables
    back_button = True         # Y / BACK pops the scene
    starfield = False          # drifting stars behind the scene

    def build(self):
        layer  = self.layer("world", projection=vs2.TUNNEL)
        sprite = layer.sprite("ship.png", x=128, y=0)
        pool   = layer.sprite_pool("shots.png", count=8, on_empty=vs2.RECYCLE)
        ground = layer.tilemap("trench.png", columns=16, rows=16)
        score  = layer.label("numerals.png", columns=5)

    def update(self):
        if joy1.held(LEFT):        ...   # level
        if joy1.just_pressed(A):   ...   # edge
        if joy1.just_released(B):  ...   # edge

    def teardown(self):
        ...                              # optional

I want to

Use

Move something

sprite.x (angle, wraps), sprite.y (inward from the rim)

Animate

sprite.frame — independent of visible

Show or hide

sprite.show(), sprite.hide(), or a whole layer.visible

Fire a bullet

pool.spawn(x, y) → sprite or None

Retire a bullet

pool.despawn(sprite), pool.despawn_all()

Hit-test

a.overlaps(b), a.first_overlap(pool)

Scroll a map

tilemap.view_x, tilemap.view_y

Edit a map

tilemap[col, row] = tile, tilemap.fill(tile)

Show text

label.text = "GAME OVER", label.write(col, row, text)

Show a score

label.set_number(value, width=5)

Text at the top of the disc

layer.label(..., flip_x=True, flip_y=True), or it reads upside-down

Leave a scene

self.pop(), self.push(other), self.switch(other)

Run something later

self.call_later(ms, callback, *args)

Play audio

vs2.audio.sound(name), vs2.audio.music(name, loop=True)

Keep a high score

vs2.saves.load(name, default), vs2.saves.save(name, value)

Know the display size

vs2.display.width (256), vs2.display.height (54)