pixi-learning/src/04/app.js
2022-11-03 03:50:22 +03:00

51 lines
1.4 KiB
JavaScript

let app = new PIXI.Application({ width: 400, height: 400, backgroundColor: 0x2a2a3a });
document.body.appendChild(app.view);
let cirleVisible = true;
const shapeCircle = new PIXI.Graphics();
const shapeRect = new PIXI.Graphics();
shapeCircle.lineStyle(4, 0x101024, 1);
shapeCircle.beginFill(0xec8a4b, 1);
shapeCircle.drawCircle(app.screen.width / 2, app.screen.height / 2, 50);
shapeCircle.endFill();
shapeRect.lineStyle(2, 0x101024, 1);
shapeRect.beginFill(0xDE3249);
shapeRect.drawRect(app.screen.width / 2 - 100, app.screen.height - 100, 200, 50);
shapeRect.endFill();
shapeRect.interactive = true;
shapeRect.cursor = 'pointer';
shapeRect.on('mouseover', (event) => {
basicText.style.fill = 0xffffff;
});
shapeRect.on('mouseout', (event) => {
basicText.style.fill = 0;
});
shapeRect.on('click', (event) => {
cirleVisible = cirleVisible ? false : true;
// shapeCircle.visible = shapeCircle.visible ? false : true;
});
const basicText = new PIXI.Text('On / Off');
basicText.anchor.set(0.5);
basicText.x = app.screen.width / 2;
basicText.y = app.screen.height - 75;
app.ticker.add((delta) => {
if (cirleVisible) {
if (shapeCircle.alpha < 1) {
shapeCircle.visible = true;
shapeCircle.alpha += 0.05;
}
}
else {
if (shapeCircle.alpha > 0) shapeCircle.alpha -= 0.05;
else shapeCircle.visible = false;
}
});
app.stage.addChild(shapeCircle, shapeRect, basicText);