jQuery addClass example
Change class name on click in jQuery
HTML
<script src="https://cdn.jsdelivr.net/npm/phaser@3.17.0/dist/phaser.js"></script>
<div>
<button type="button" id="destroy">
Destroy
</button>
<div id="phaser-example" />
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#banner-message {
background: #fff;
border-radius: 4px;
padding: 20px;
font-size: 25px;
text-align: center;
transition: all 0.2s;
margin: 0 auto;
width: 300px;
}
button {
background: #0084ff;
border: none;
border-radius: 5px;
padding: 8px 14px;
font-size: 15px;
color: #fff;
}
#banner-message.alt {
background: #0084ff;
color: #fff;
margin-top: 40px;
width: 200px;
}
#banner-message.alt button {
background: #fff;
color: #000;
}
JavaScript
// find elements
var button = $("#destroy")
button.click(function(){
console.log("Issues here:")
game.destroy(true)
})
class BootScene extends Phaser.Scene {
constructor () {
super({ key: 'BootScene' })
}
preload () {
/* this.load.image('red', 'assets/sprites/columns-red.png') */;
}
create () {
this.scene.start('PlayScene')
}
}
class PlayScene extends Phaser.Scene {
constructor (config)
{
super({key: 'PlayScene'})
}
create (data)
{
this.matter.world.setBounds().disableGravity();
var circ = this.matter.add.image(200, 50, 'red');
// Change the body to a Circle with a radius of 48px
circ.setBody({
type: 'circle',
radius: 48
});
// Just make the body move around and bounce
circ.setVelocity(6, 3);
circ.setAngularVelocity(0.01);
circ.setBounce(1);
circ.setFriction(0, 0, 0);
}
}
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#1b1464',
parent: 'phaser-example',
physics: {
default: 'matter',
matter: {
debug: true
}
},
scene: [BootScene,PlayScene]
};
var game = new Phaser.Game(config);