Kaplay.Context
Types
drawLinesOptions
Options for drawing connected lines
type drawLinesOptions = { pts: array<Kaplay.Vec2.t>, pos?: Kaplay.Vec2.t, color?: Kaplay.Types.color, opacity?: float, width?: float, radius?: array<float>, join?: Kaplay.Types.lineJoin, cap?: Kaplay.Types.lineCap, bias?: float, miterLimit?: float,}
Fields
getOptions
type getOptions = {recursive?: bool, liveUpdate?: bool}
Fields
htmlCanvasElement
type htmlCanvasElement
kaplayOptions
Initialize KAPLAY context. The starting point of all KAPLAY games.
type kaplayOptions = { width?: int, height?: int, global?: bool, background?: string, scale?: float, letterbox?: bool, canvas?: htmlCanvasElement, crisp?: bool, pixelDensity?: float, spriteAtlasPadding?: int,}
Fields
levelOptions
type levelOptions = { tileWidth?: float, tileHeight?: float, tiles: Dict.t<unit => array<Kaplay.Types.comp>>,}
Fields
loadSpriteAnimation
type loadSpriteAnimation = { from?: int, to?: int, loop?: bool, pingpong?: bool, speed?: float, frames?: array<int>,}
Fields
loadSpriteOptions
type loadSpriteOptions = { sliceX?: int, sliceY?: int, anims?: Dict.t<loadSpriteAnimation>, anim?: string, frames?: array<Kaplay.Types.quad>, singular?: bool,}
Fields
playOptions
type playOptions = {seek?: float}
Fields
t
type t = { debug: Kaplay.Debug.t, easings: Kaplay.Types.easingMap,}
Fields
Values
add
let add: (t, array<Kaplay.Types.comp>) => 't
Parameters
Return type
addLevel
let addLevel: (t, array<string>, levelOptions) => Level.t
Return type
center
let center: t => Kaplay.Vec2.t
Parameters
Return type
clamp
let clamp: (t, int, int, int) => int
Return type
clampFloat
let clampFloat: (t, float, float, float) => float
Return type
colorFromHex
let colorFromHex: (t, string) => Kaplay.Types.color
Return type
colorFromRGB
let colorFromRGB: (t, int, int, int) => Kaplay.Types.color
Return type
deg2rad
Convert degrees to radians
let deg2rad: (t, float) => float
Return type
destroy
let destroy: (t, 't) => unit
Parameters
Return type
drawLines
let drawLines: (t, drawLinesOptions) => unit
Return type
dt
Get the delta time in seconds since last frame.
let dt: t => float
Parameters
Return type
getCamPos
let getCamPos: t => Kaplay.Vec2.t
Parameters
Return type
getCursor
let getCursor: t => Kaplay.Types.cursor
Parameters
Return type
getGameObjects
let getGameObjects: (t, string, ~options: getOptions=?) => array<'t>
Return type
getSprite
let getSprite: (t, string) => Kaplay.Asset.t<Kaplay.SpriteData.t>
Return type
go
let go: (t, string, ~data: 'a=?) => unit
Return type
goWithData
go(context, sceneName, ~data=?)
Go to a scene with data passed to the scene.
let goWithData: (t, string, 'a) => unit
Return type
height
let height: t => float
Parameters
Return type
isKeyDown
let isKeyDown: (t, Kaplay.Types.key) => bool
Return type
kaplay
let kaplay: (~initOptions: kaplayOptions=?) => t
Parameters
Return type
loadBean
let loadBean: (t, ~name: string=?) => unit
Return type
loadMusic
Like loadSound(), but the audio is streamed and won't block loading. Use this for big audio files like background music.
let loadMusic: (t, string, string) => unit
Return type
loadShader
loadShader(Context.t, name, shader code)
let loadShader: (t, string, ~vert: string=?, ~frag: string=?) => unit
Return type
loadSound
Use for short sound effects, use loadMusic
for background music.
let loadSound: (t, string, string) => unit
Return type
loadSprite
let loadSprite: (t, string, string, ~options: loadSpriteOptions=?) => unit
Return type
loop
Run the function every n seconds.
let loop: ( t, float, unit => unit, ~maxLoops: int=?, ~waitFirst: bool=?,) => Kaplay.TimerController.t
Return type
mathCircle
center, radius
let mathCircle: (t, Kaplay.Vec2.t, float) => Kaplay.Math.Shape.t
Return type
mathPolygon
let mathPolygon: (t, array<Kaplay.Vec2.t>) => Kaplay.Math.Shape.t
Return type
mathRect
let mathRect: (t, Kaplay.Vec2.t, float, float) => Kaplay.Math.Shape.t
Return type
mousePos
Get current mouse position (without camera transform).
let mousePos: t => Kaplay.Vec2.t
Parameters
Return type
on
on(context, event, tag, (gameObject, arg) => unit)
Register an event on all game objs with certain tag.
let on: ( t, ~event: string, ~tag: string, ('t, 'arg) => unit,) => unit
Return type
onClick
let onClick: (t, unit => unit) => unit
Return type
onClickWithController
let onClickWithController: (t, unit => unit) => Kaplay.KEventController.t
Return type
onClickWithTag
let onClickWithTag: (t, string, 't => unit) => Kaplay.KEventController.t
Return type
onKeyDown
Holding the key down
let onKeyDown: (t, Kaplay.Types.key => unit) => unit
Return type
onKeyDownWithController
Holding the key down
let onKeyDownWithController: (t, Kaplay.Types.key => unit) => Kaplay.KEventController.t
Return type
onKeyPress
Hitting the key
let onKeyPress: (t, Kaplay.Types.key => unit) => unit
Return type
onKeyPressWithController
Hitting the key
let onKeyPressWithController: (t, Kaplay.Types.key => unit) => Kaplay.KEventController.t
Return type
onKeyRelease
Lifting the key up
let onKeyRelease: (t, Kaplay.Types.key => unit) => unit
Return type
onKeyReleaseWithController
Lifting the key up
let onKeyReleaseWithController: (t, Kaplay.Types.key => unit) => Kaplay.KEventController.t
Return type
onLoad
Register an event that runs when all assets finished loading.
let onLoad: (t, unit => unit) => unit
Return type
onMouseMove
onMouseMove(context, (pos, delta) => unit)
Register an event that runs whenever user moves the mouse.
let onMouseMove: (t, (Kaplay.Vec2.t, Kaplay.Vec2.t) => unit) => unit
Return type
onMouseMoveWithController
onMouseMove(context, (pos, delta) => KEventController.t)
Register an event that runs whenever user moves the mouse.
let onMouseMoveWithController: ( t, (Kaplay.Vec2.t, Kaplay.Vec2.t) => unit,) => Kaplay.KEventController.t
Return type
onMousePress
Register an event that runs whenever user presses a mouse button.
let onMousePress: (t, Kaplay.Types.mouseButton => unit) => unit
Return type
onMousePressWithController
Register an event that runs whenever user presses a mouse button.
let onMousePressWithController: ( t, Kaplay.Types.mouseButton => unit,) => Kaplay.KEventController.t
Return type
onMouseRelease
Register an event that runs whenever user releases a mouse button.
let onMouseRelease: (t, Kaplay.Types.mouseButton => unit) => unit
Return type
onMouseReleaseWithController
Register an event that runs whenever user releases a mouse button.
let onMouseReleaseWithController: ( t, Kaplay.Types.mouseButton => unit,) => Kaplay.KEventController.t
Return type
onTouchEnd
let onTouchEnd: (t, (Kaplay.Vec2.t, Kaplay.Types.touch) => unit) => unit
Return type
onTouchEndWithController
let onTouchEndWithController: ( t, (Kaplay.Vec2.t, Kaplay.Types.touch) => unit,) => Kaplay.KEventController.t
Return type
onTouchMove
let onTouchMove: (t, (Kaplay.Vec2.t, Kaplay.Types.touch) => unit) => unit
Return type
onTouchMoveWithController
let onTouchMoveWithController: ( t, (Kaplay.Vec2.t, Kaplay.Types.touch) => unit,) => Kaplay.KEventController.t
Return type
onTouchStart
let onTouchStart: (t, (Kaplay.Vec2.t, Kaplay.Types.touch) => unit) => unit
Return type
onTouchStartWithController
let onTouchStartWithController: ( t, (Kaplay.Vec2.t, Kaplay.Types.touch) => unit,) => Kaplay.KEventController.t
Return type
onUpdate
let onUpdate: (t, unit => unit) => unit
Return type
onUpdateWithController
let onUpdateWithController: (t, unit => unit) => Kaplay.KEventController.t
Return type
onWithController
on(context, event, tag, (gameObject, arg) => unit)
Register an event on all game objs with certain tag.
let onWithController: ( t, ~event: string, ~tag: string, ('t, 'arg) => unit,) => Kaplay.KEventController.t
Return type
play
let play: (t, string, ~options: playOptions=?) => Kaplay.AudioPlay.t
Return type
quad
let quad: (t, float, float, float, float) => Kaplay.Types.quad
Return type
rad2deg
Convert radians to degrees
let rad2deg: (t, float) => float
Return type
randf
let randf: (t, float, float) => float
Return type
randi
let randi: (t, int, int) => int
Return type
scene
let scene: (t, string, 'a => unit) => unit
Return type
setBackground
let setBackground: (t, Kaplay.Types.color) => unit
Return type
setCamPos
let setCamPos: (t, Kaplay.Vec2.t) => unit
Return type
setCursor
let setCursor: (t, Kaplay.Types.cursor) => unit
Return type
setFullscreen
let setFullscreen: (t, bool) => unit
Return type
setGravity
let setGravity: (t, float) => unit
Return type
tagComponent
let tag: string => Kaplay.Types.comp
Parameters
Return type
time
Get the total time in seconds since beginning.
let time: t => float
Parameters
Return type
toScreen
Transform a point from world position (relative to the root) to screen position (relative to the screen).
let toScreen: (t, Kaplay.Vec2.t) => Kaplay.Vec2.t
Return type
toWorld
Transform a point from screen position (relative to the screen) to world position (relative to the root).
let mousePos = k->Context.mousePos
let worldPos = k->Context.toWorld(mousePos)
let toWorld: (t, Kaplay.Vec2.t) => Kaplay.Vec2.t
Return type
tween
tween(context, from, to, duration in seconds, setValue, easeFunc=?) => unit
Useful to change a property of a Game Object over time.
k
->Context.tween(
~from=-15.,
~to_=0.,
~duration=0.5,
~setValue=Bird.setAngle(bird, ...),
)
let tween: ( t, ~from: 'v, ~to_: 'v, ~duration: float, ~setValue: 'v => unit, ~easeFunc: Kaplay.Types.easeFunc=?,) => unit
Return type
tweenWithController
tween(context, from, to, duration in seconds, setValue, easeFunc=?) => TweenController.t
Useful to change a property of a Game Object over time.
k
->Context.tween(
~from=-15.,
~to_=0.,
~duration=0.5,
~setValue=Bird.setAngle(bird, ...),
)
let tweenWithController: ( t, ~from: 'v, ~to_: 'v, ~duration: float, ~setValue: 'v => unit, ~easeFunc: Kaplay.Types.easeFunc=?,) => Kaplay.TweenController.t
Return type
vec2
let vec2: (t, float, float) => Kaplay.Vec2.t
Return type
vec2Down
let vec2Down: t => Kaplay.Vec2.t
Parameters
Return type
vec2FromXY
let vec2FromXY: (t, float) => Kaplay.Vec2.t
Return type
vec2Left
let vec2Left: t => Kaplay.Vec2.t
Parameters
Return type
vec2One
let vec2One: t => Kaplay.Vec2.t
Parameters
Return type
vec2Right
let vec2Right: t => Kaplay.Vec2.t
Parameters
Return type
vec2Up
let vec2Up: t => Kaplay.Vec2.t
Parameters
Return type
vec2Zero
let vec2Zero: t => Kaplay.Vec2.t
Parameters
Return type
wait
wait(context, seconds, callback)
Run the function after n seconds.
let wait: (t, float, unit => unit) => unit
Return type
waitWithController
wait(context, seconds, callback)
Run the function after n seconds.
let waitWithController: (t, float, unit => unit) => Kaplay.TimerController.t
Return type
width
let width: t => float
Parameters
Return type
Modules
Level
Types
t
type t
Values
spawn
let spawn: (t, array<Kaplay.Types.comp>, Kaplay.Vec2.t) => 't