通过使用GraphicsGeometry对象创建图形对象,我能够提高性能。相关代码如下所示。
const box = new PIXI.Graphics();
box.lineStyle(1, PE_BORDER_COLOR, 0.4);
box.beginFill(PE_COLOR, 0.8);
box.drawRoundedRect(0, 0, PE_WIDTH, PE_HEIGHT, 2);
box.endFill();
box.lineStyle(1, ROUTER_COLOR, 0.2);
box.beginFill(ROUTER_COLOR, 0.4);
box.drawCircle(ROUTER_OFFSET, ROUTER_OFFSET, ROUTER_RADIUS);
box.endFill();
box.lineStyle(1, CE_COLOR, 0.2);
box.beginFill(CE_COLOR, 0.4);
box.drawRect(CE_OFFSET, CE_OFFSET, CE_SIZE, CE_SIZE);
box.endFill();
for (let i = 0; i < width; ++i) {
for (let j = 0; j < height; ++j) {
const x = i * PE_WIDTH + i * VIZ_AREA_WIDTH_GAP;
const y = j * PE_HEIGHT + j * VIZ_AREA_HEIGHT_GAP;
const boxG = new PIXI.Graphics(box.geometry);
boxG.x = x;
boxG.y = y;
app.stage.addChild(boxG);
}
}
在上面的代码中,每个正方形都被渲染为一个通用的GraphicsGeometry对象。该对象用于创建图形对象,并放置在特定位置。