nativescript-pixi
由 triniwiz 编写 | v1.0.0-alpha1
用于在 NativeScript 中使用 pixi.js 的插件
npm i --save nativescript-pixi

nativescript-pixi

npm npm Build Status

安装

npm i three nativescript-pixi

用法

<GridLayout width="100%" height="100%">
<canvas:TNSCanvas width="100%" height="100%" id="canvas" ready="onReady"/>
</GridLayout>
import * as PIXI from "pixi.js";
import { TNSPIXIApplication } from "nativescript-pixi";
// Create the Application by passing the canvas view object to it
function onReady(args) {
const canvas = args.object;
const app = new TNSPIXIApplication({
canvas,
backgroundColor: 0x1099bb,
});
app.loader.add("bg_grass", "~/assets/images/bg_grass.jpg").load(build);

function build() {
// Create a new texture
const texture = app.loader.resources.bg_grass.texture;

// Create the simple plane
const verticesX = 10;
const verticesY = 10;
const plane = new PIXI.SimplePlane(texture, verticesX, verticesY);

plane.x = 100;
plane.y = 100;

app.stage.addChild(plane);

// Get the buffer for vertice positions.
const buffer = plane.geometry.getBuffer("aVertexPosition") as any;

// Listen for animate update
app.ticker.add((delta) => {
// Randomize the vertice positions a bit to create movement.
for (let i = 0; i < buffer.data.length; i++) {
buffer.data[i] += Math.random() - 0.5;
}
buffer.update();
});
}
}

例如输出

Output

例如输出

许可证

Apache License 版本 2.0,2004 年 1 月