api.module
This package holds more than this page lists. See all of its files in its world.
README.md
api
The front door of the twoDKit: turn a scene into a playable multiplayer 2D platformer in three calls from its build.luau: place a level typed as text, write the player template (body, sprite, controller, pixel-perfect camera, spawn point), and add the HUD. It also re-exports the kit's registries so one require reaches everything.
local PP = require("twoDKit.api")
function content()
PP.level({ theme = "grassland", text = [[
##############################
#............................#
#..P.....o.....====.......G..#
####..^^..####......M....#####
]] })
PP.player({ character = "fox", feel = "tight", lives = 3 })
PP.hud()
end
Building a scene
PP.level(opts) -> entity: spawns aLevel2Dentity (namedopts.name, default "Level") with its bottom-left corner atopts.position(default the origin). Passes ontext,theme(default grassland),tileset,background,camera,seed,decorations,moverLength,moverTravel,moverSpeed,killDepth,roomWidth,roomHeight.PP.player(opts?) -> { prototype, body, rig, spawn }: writes the scene's player template so every person who joins gets their own: aPlayerPrototypewith abodycarryingSprite2D+Player2D(character, default knight;feel, default tight), an owner-onlyCameraRigwith an orthographicCameradriven byCamera2D(camerastyle, default pixelPerfect; optionaltargetHeight), and aPlayerSpawnatopts.positionor thePof the lastPP.level. Withlives > 0it also adds aTrapline.Course(lives, respawn at checkpoints).PP.hud(opts?) -> entity: addsHud2D(showStyles, default true;title).PP.startOf(text, ox?, oy?) -> { x, y, z }: world position (feet) of thePin level text placed at (ox, oy), or 2 tiles in from the corner.
In play (this peer)
PP.localPlayer(): the body this peer controls, or nil until it spawns.PP.setTheme(id): switch every level to a theme (tile set + background).PP.setCharacter(id),PP.setFeel(id): change this peer's player (synced to everyone).PP.setCamera(style): pixelPerfect, smooth or rooms on this peer's camera.
Re-exports
PP.Catalog, PP.Feels, PP.Level, PP.Levels, and PP.registerCharacter, PP.registerTileset, PP.registerBackground, PP.registerTheme, PP.registerFeel (see twoDKit.catalog and twoDKit.feels).