Phaser是用JavaScript编写的HTML端2D游戏引擎
<!DOCTYPE html>
<html lang="en">
<head>
<title>App</title>
<script src="https://cdn.jsdelivr.net/npm/phaser@3.15.1/dist/phaser-arcade-physics.min.js"></script>
</head>
<body>
<script>
new Phaser.Game({
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: {
y: 100
}
}
},
scene: {
preload: function () {
this.load.image('pineapple', 'pineapple.png');
this.load.image('apple', 'apple.png')
},
create: function () {
const particles = this.add.particles('pineapple');
const emitter = particles.createEmitter({
speed: 100,
scale: {
start: 0.5,
end: 0
}
});
const logo = this.physics.add.image(0, 0, 'apple');
logo.setVelocity(1000, 1500);
logo.setBounce(1, 1);
logo.setCollideWorldBounds(true);
emitter.startFollow(logo);
}
}
});
</script>
</body>
</html>