【发布时间】:2019-10-02 23:18:22
【问题描述】:
我刚开始使用 Pixi.js。我想在画布的中心放置多条线并旋转它们。所以我把线放在一个容器中,并将轴心点设置在容器的中心。然后我将容器的位置设置为画布的中心,但它没有居中。为什么?
var app = new PIXI.Application({
width: 200,
height: 200,
antialias: true
});
app.renderer.backgroundColor = 0x061639;
document.body.appendChild(app.view);
function createLine(offset){
let line = new PIXI.Graphics()
line.lineStyle(25, 0xBB0000);
line.x = offset;
line.y = 0;
line.moveTo(0, 0);
line.lineTo(0, 100);
return line;
}
let line1 = createLine(0);
let line2 = createLine(50);
let container = new PIXI.Container();
container.addChild(line1, line2);
container.pivot.x = container.width/2;
container.pivot.y = container.height/2;
container.x = app.screen.width/2;
container.y = app.screen.height/2;
//container.rotation = Math.PI/180*45; //rotate 45 degrees
app.stage.addChild(container);
<!doctype html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.8.2/pixi.js"></script>
</head>
<body></body>
</html>
【问题讨论】:
标签: pixi.js