diff --git a/example/customRenderer/App.js b/example/customRenderer/App.js new file mode 100644 index 0000000..e772870 --- /dev/null +++ b/example/customRenderer/App.js @@ -0,0 +1,33 @@ +import { h, ref } from "../../lib/mini-vue.esm.js"; +import { game } from "./game.js"; + +export default { + name: "App", + setup() { + // 通过 ticker 来去更新 x 的值 + + const x = ref(0); + const y = ref(0); + let dir = 1; + const speed = 2; + + game.ticker.add(() => { + if (x.value > 400) { + dir = -1; + } else if (x.value < 0) { + dir = 1; + } + + x.value += speed * dir; + }); + + return { + x, + y, + }; + }, + + render() { + return h("rect", { x: this.x, y: this.y }); + }, +}; diff --git a/example/customRenderer/game.js b/example/customRenderer/game.js new file mode 100644 index 0000000..0c1f09c --- /dev/null +++ b/example/customRenderer/game.js @@ -0,0 +1,10 @@ +export const game = new PIXI.Application({ + width: 500, + height: 500, +}); + +document.body.append(game.view); + +export function createRootContainer() { + return game.stage; +} diff --git a/example/customRenderer/index.html b/example/customRenderer/index.html new file mode 100644 index 0000000..f5d2703 --- /dev/null +++ b/example/customRenderer/index.html @@ -0,0 +1,14 @@ + + +
+ + +