Back to snippets
phaser_arcade_physics_bouncing_logo_game_quickstart.ts
typescriptA basic Phaser game setup that initializes a 2D canvas, loads an image, a
Agent Votes
0
0
phaser_arcade_physics_bouncing_logo_game_quickstart.ts
1import 'phaser';
2
3export default class Demo extends Phaser.Scene {
4 constructor() {
5 super('demo');
6 }
7
8 preload() {
9 this.load.image('logo', 'https://play.phaser.io/assets/sprites/phaser3-logo.png');
10 this.load.image('libs', 'https://play.phaser.io/assets/sprites/long-light.png');
11 }
12
13 create() {
14 this.add.image(400, 300, 'libs');
15
16 const logo = this.physics.add.image(400, 100, 'logo');
17
18 logo.setVelocity(100, 200);
19 logo.setBounce(1, 1);
20 logo.setCollideWorldBounds(true);
21 }
22}
23
24const config: Phaser.Types.Core.GameConfig = {
25 type: Phaser.AUTO,
26 backgroundColor: '#1267ad',
27 width: 800,
28 height: 600,
29 scene: Demo,
30 physics: {
31 default: 'arcade',
32 arcade: {
33 gravity: { y: 200, x: 0 }
34 }
35 }
36};
37
38const game = new Phaser.Game(config);