JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/3.22.0/phaser.min.js"></script>
<div id='phaser-example'></div>
<head>
<meta charset="utf-8" />
<style>
canvas {
/* And see postBoot() in JS */
width: 100%;
height: 100%;
object-fit: contain;
/* <https://caniuse.com/#feat=object-fit> */
}
</style>
</head>
JavaScript
var f = {}
var o = {}
f.init_test = (g) => {
g.matter.world.resetCollisionIDs();
cat0 = g.matter.world.nextCategory();
f.create_terrain = (g) => {
o.limit_ball_left = g.matter.add.image(0, 320, "limit_v", null, {
restitution: 0,
isStatic: true
}).setVisible(true).setCollisionCategory(cat0)
o.limit_ball_left.name = 'left'
o.limit_ball_right = g.matter.add.image(300, 320, "limit_v", null, {
restitution: 0,
isStatic: true
}).setVisible(true).setCollisionCategory(cat0)
o.limit_ball_right.name = 'right'
}
f.create_terrain(g)
o.ball = g.matter.add.image(160, 50, 'ball').setVelocity(10).setBounce(1)
window.setInterval(function () {
g.scene.stop('test')
g.scene.start('test')
}, 2000);
}
const my_game = {
init: () => {
var boot = new Phaser.Class({
Extends: Phaser.Scene,
initialize: function boot() {
Phaser.Scene.call(this, {
key: 'boot'
});
},
preload: function () {
this.load.image("ball", "https://i.postimg.cc/rFFByHRS/ball.png");
this.load.image("limit_v", "https://i.postimg.cc/JnFkyv4G/limit-v.png");
},
create: function () {
this.scene.launch('test')
},
});
var test = new Phaser.Class({
Extends: Phaser.Scene,
initialize: function main() {
Phaser.Scene.call(this, {
key: 'test'
});
},
create: function () {
f.init_test(this)
},
update: function () {},
});
var config = {
type: Phaser.WEBGL,
width: 320,
height: 640,
backgroundColor: '#000000',
parent: 'phaser-game',
physics: {
default:...