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

40 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Создаём приложение app...
let app = new PIXI.Application({ width: 400, height: 400 });
document.body.appendChild(app.view); // и добавляем его на страницу
// Отключаем сглаживание
PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.NEAREST;
// Добавляем фон
app.renderer.backgroundColor = 0x779911;
console.log(app.renderer.options);
// Создаём спрайт и добавляем его на сцену
let sprite = PIXI.Sprite.from('/assets/chest.png');
// Установим точку привязки спрайта по центру
sprite.anchor.set(0.5);
// Увеличим размер спрайта вдвое
sprite.width *= 5;
sprite.height *= 5;
// Разместим спрайт по центру
sprite.y = app.screen.height / 2;
sprite.x = app.screen.width / 2;
app.stage.addChild(sprite);
sprite.interactive = true;
sprite.cursor = 'wait';
sprite.on('click', (event) => {
alert('bye!');
sprite.destroy();
console.log(sprite);
});
// Добавляем ticker для перемещения спрайта туда-сюда
app.ticker.add((delta) => {
if (sprite._destroyed != true) {
sprite.rotation += 0.05 * delta;
}
});