Migrating from v2000 to v3000
obj._id
is renamed to obj.id
const obj = add([
pos(300, 200),
sprite("bean"),
area(),
])
console.log(obj._id)
console.log(obj.id)
origin()
is renamed to anchor()
add([
sprite("bean"),
origin("center"),
])
add([
sprite("bean"),
anchor("center"),
])
obj.onHover()
in area()
comp is renamed to obj.onHoverUpdate()
, obj.onHover()
now only runs once when obj is hovered
const obj = add([
pos(300, 200),
sprite("bean"),
area(),
])
obj.onHover(() => {
console.log("this will print every frame when obj is hovered")
}, () => {
console.log("this will print every frame when obj is not hovered")
})
obj.onHover(() => {
console.log("this will run once when obj is hovered")
})
obj.onHoverUpdate(() => {
console.log("this will run every frame when obj is hovered")
})
obj.onHoverEnd(() => {
console.log("this will run once when obj stopped being hovered")
})
obj.pushOut()
is renamed to obj.resolveCollision()
const player = add([
sprite("bean"),
pos(300, 200),
area(),
])
player.pushOut(rock)
player.resolveCollision(rocker)
solid()
comp becomes an option in body({ isStatic: true })
add([
sprite("bean"),
area(),
body(),
solid(),
])
add([
sprite("bean"),
area(),
body({ isStatic: true }),
])
- gravity now needs to be manually enabled,
gravity()
is renamed to setGravity()
and getGravity()
add([
pos(100, 100),
sprite("bean"),
area(),
body(),
])
setGravity(1600)
add([
pos(100, 100),
sprite("bean"),
area(),
body(),
])
body.weight
is renamed to body.gravityScale
add([
body({ weight: 2 }),
])
add([
body({ gravityScale: 2 }),
])
body.doubleJump()
is removed in favor of new doubleJump()
component
const obj = add([
pos(100, 100),
sprite("bean"),
area(),
body(),
])
obj.doubleJump()
const obj = add([
pos(100, 100),
sprite("bean"),
area(),
body(),
doubleJump(),
])
obj.doubleJump()
body.onFall()
is renamed to body.onFallOff()
, body.onFall()
now runs when body is in the air and starts to fall
gravity(1600)
const obj = add([
pos(100, 100),
sprite("bean"),
area(),
body(),
])
obj.onFall(() => {
console.log("this will print when object falls off a platform")
})
obj.onFallOff(() => {
console.log("this will print when object falls off a platform")
})
obj.onFall(() => {
console.log("this will print when object is in the air and starts falling")
})
- removed
outview()
in favor of offscreen()
, which is less accurate but much faster
add([
sprite("flower"),
outview({ hide: true }),
])
add([
sprite("flower"),
offscreen({ hide: true, distance: 64 }),
])
- removed
cleanup()
in favor of offscreen({ destroy: true })
add([
pos(player.pos),
sprite("bullet"),
cleanup(),
])
add([
pos(player.pos),
sprite("bullet"),
offscreen({ destroy: true }),
])
sprite.flipX
and sprite.flipY
becomes properties instead of functions
const bean = add([
sprite("bean")
])
bean.flipX(true)
bean.flipX = true
sprite.onAnimStart()
and sprite.onAnimEnd()
now triggers on any animation
const bean = add([
sprite("bean")
])
bean.onAnimStart("walk", () => {
})
bean.onAnimStart((anim) => {
if (anim === "walk") {
}
})
obj.scale
now is always a Vec2
scale(2)
obj.scale
loadFont()
now only loads .ttf
, .otf
, .woff
etc fonts that browser support, use loadBitmapFont()
to load bitmap fonts
loadFont("unscii", "/examples/fonts/unscii_8x8.png", 8, 8)
loadBitmapFont("unscii", "/examples/fonts/unscii_8x8.png", 8, 8)
loadFont("apl386", "/examples/fonts/apl386.ttf")
- removed builtin fonts
apl386
, apl386o
, sink
and sinko
, using browser built-in monospace
font as default font now
loadFont("apl386", "/examples/fonts/apl386.ttf")
loadBitmapFont("sink", "/examples/fonts/sink_6x8.png")
loadFont("apl386", "/examples/fonts/apl386.ttf", {
outline: 3,
})
- changed vertex format from
vec3
to vec2
(only applied in shaders)
loadShader("test", null, `
vec4 frag(vec3 pos, vec2 uv, vec4 color, sampler2D tex) {
return def_frag();
}
`)
loadShader("test", null, `
vec4 frag(vec2 pos, vec2 uv, vec4 color, sampler2D tex) {
return def_frag();
}
`)
anchor
(previously origin
) no longer controls text alignment (only controls the anchor of the whole text area), use text({ align: "left" })
option for text alignment
add([
pos(center()),
origin("center"),
text("oh hi"),
])
add([
pos(center()),
anchor("center"),
text("oh hi", { align: "center" }),
])
- changed text styling syntax to bbcode
const textOpts = {
styles: {
"green": {
color: rgb(128, 128, 255),
},
"wavy": (idx, ch) => ({
color: hsl2rgb((time() * 0.2 + idx * 0.1) % 1, 0.7, 0.8),
pos: vec2(0, wave(-4, 4, time() * 6 + idx * 0.5)),
}),
},
}
add([
text("[oh hi].green here's some [styled].wavy text", textOpts),
])
add([
text("[green]oh hi[/green] here's some [wavy]styled[/wavy] text", textOpts),
])
- changed all event handlers to return an
EventController
object, instead of a function to cancel
const cancel = onUpdate(() => { })
cancel()
const ev = onUpdate(() => { })
ev.paused = true
ev.cancel()
- changed the interface for
addLevel()
addLevel([
"@ ^ $$",
"=======",
], {
width: 32,
height: 32,
"=": () => [
sprite("grass"),
area(),
body({ isStatic: true }),
],
"$": () => [
sprite("coin"),
area(),
"coin",
],
any: (symbol) => {
if (symbol === "@") {
return [ ]
}
},
})
addLevel([
"@ ^ $$",
"=======",
], {
tileWidth: 32,
tileHeight: 32,
tiles: {
"=": () => [
sprite("grass"),
area(),
body({ isStatic: true }),
],
"$": () => [
sprite("coin"),
area(),
"coin",
],
},
wildcardTile: (symbol) => {
if (symbol === "@") {
return [ ]
}
},
})