Я использую графическую библиотеку JavaScript Phaser 3: https://phaser.io/phaser3
У меня есть элемент canvas, который я ранее создал вне библиотеки.Теперь я хочу нарисовать этот элемент холста на экране с помощью Phaser 3. В качестве примера игрушки рассмотрим следующий код:
const game = new Phaser.Game({
type: Phaser.AUTO,
width: 1000,
height: 1000,
scene: {
create,
},
});
function create() {
// Create a circle
// From: https://www.w3schools.com/tags/canvas_arc.asp
const circle = document.createElement('canvas');
const ctx = circle.getContext('2d');
ctx.beginPath();
ctx.arc(100, 75, 50, 0, 2 * Math.PI);
ctx.stroke();
// Draw the circle using Phaser 3
const circleTexture = this.textures.createCanvas('circle');
circleTexture.setDataSource(circle);
circleTexture.refresh();
const circleImage = this.add.image(150, 200, 'circle');
}
При запуске этот код ничего не рисует на экране.Как правильно выполнить эту задачу?