Godot 风格的节点树
Node、Scene、生命周期、类型化的信号、Groups、Autoload、Timer、Tween。继承节点类写游戏对象,没有编辑器,也没有场景文件。
import { Node2D, Scene, v } from 'sapling2d'
import { startGame } from 'sapling2d/browser'
class Mover extends Node2D {
speed = 120 // 像素/秒
override process(dt: number) {
this.x += this.speed * dt
}
}
class Main extends Scene {
override ready() {
this.add(new Mover({ position: v(100, 200) }))
}
}
await startGame({ main: Main })