Skip to content

John4650-hub/phaser-3-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 

Repository files navigation

Creating a scene in phaser

  • with classes We can create scenes in phaser using es6 classes as below. I prefer arcade physics and rarely use matter:
class mainScene extends Phaser.Scene{
	constructor(){
		super({key:'mainscene'});
	}
	preload(){}
	create(){}
	update(){}
}

const config = {
	type: Phaser.AUTO,
	parent: 'div_id',
	scale: {
	mode: Phaser.Scale.FIT
	},
	width:800,
	height:600,
	physics: {
		default:'arcade',
		arcade:
			{
			gravity:{y:200}
			debug:false
			}
	},
	scene:[mainScene]
}
const game = Phaser.Game(config):
  • The other way: I use this way when am only working in one scene
const config = {
	type: Phaser.AUTO,
	parent: 'div_id',
	scale: {
	mode: Phaser.Scale.FIT
	},
	width:800,
	height:600,
	physics: {
		default:'arcade',
		arcade:
			{
			gravity:{y:200}
			debug:false
			}
	},
	scene:{
		preload,
		create,
		update
	}
}
const game = Phaser.Game(config):

function preload(){}
function create(){}
function update(){}

Loading in things

We do this either in the config or the preload

images

this.load.image('imgKey','imageSrc');

spritesheet

this.load.spritesheet('key','spritesheetSrc'{frameWidth:'widthOfTheImage/numOfColumns',frameHeight:'heightOfTheImage/numOfRows'});

audio

this.load.audio('audioKey','audioSrc');

About

Some essential phaser 3 code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published