class Example extends Phaser.Scene {
super({ key: "Example" });
this.worldWidth = config.width * 2;
this.worldHeight = config.height * 2;
this.physics.world.setBounds(
this.player = this.add.circle(400, 200, 10, 0xffff00);
this.physics.add.existing(this.player);
this.player.body.setCollideWorldBounds(true);
this.cameras.main.setBounds(
this.cameras.main.startFollow(this.player, true, 0.1, 0.1);
this.cross = this.add.graphics();
this.keys = this.input.keyboard.addKeys({
up: Phaser.Input.Keyboard.KeyCodes.W,
left: Phaser.Input.Keyboard.KeyCodes.A,
down: Phaser.Input.Keyboard.KeyCodes.S,
right: Phaser.Input.Keyboard.KeyCodes.D
this.player.body.setVelocity(0);
if (this.keys.left.isDown) {
this.player.body.setVelocityX(-this.playerSpeed);
} else if (this.keys.right.isDown) {
this.player.body.setVelocityX(this.playerSpeed);
if (this.keys.up.isDown) {
this.player.body.setVelocityY(-this.playerSpeed);
} else if (this.keys.down.isDown) {
this.player.body.setVelocityY(this.playerSpeed);
const lineStyle = { color: 0xffffff, width: 1 };
let graphics = this.add.graphics(lineStyle);
for (let x = this.worldWidth / -2; x <= this.worldWidth / 2; x += 100) {
subX < x + 100 && subX <= this.worldWidth;
graphics.lineStyle(1, 0x666666);
graphics.moveTo(subX, this.worldHeight / -2);
graphics.lineTo(subX, this.worldHeight / 2);
for (let y = this.worldHeight / -2; y <= this.worldHeight / 2; y += 100) {
subY < y + 100 && subY <= this.worldHeight;
graphics.lineStyle(1, 0x666666);
graphics.moveTo(this.worldWidth / -2, subY);
graphics.lineTo(this.worldWidth / 2, subY);
for (let x = this.worldWidth / -2; x <= this.worldWidth / 2; x += 100) {
graphics.lineStyle(2, 0x000000);
graphics.moveTo(x, this.worldHeight / -2);
graphics.lineTo(x, this.worldHeight / 2);
for (let y = this.worldHeight / -2; y <= this.worldHeight / 2; y += 100) {
graphics.lineStyle(2, 0x000000);
graphics.moveTo(this.worldWidth / -2, y);
graphics.lineTo(this.worldWidth / 2, y);
for (let i = this.worldWidth / -2; i <= this.worldWidth / 2; i += 100) {
.text(i, 5, i.toString(), {
backgroundColor: "#000000"
for (let i = this.worldHeight / -2; i <= this.worldHeight / 2; i += 100) {
.text(5, i, i.toString(), {
backgroundColor: "#000000"
this.cross.lineStyle(2, 0xff0000);
const camCenterX = this.cameras.main.midPoint.x;
const camCenterY = this.cameras.main.midPoint.y;
this.cross.moveTo(camCenterX - 20, camCenterY);
this.cross.lineTo(camCenterX + 20, camCenterY);
this.cross.moveTo(camCenterX, camCenterY - 20);
this.cross.lineTo(camCenterX, camCenterY + 20);
const game = new Phaser.Game(config);
activateControls(["W", "A", "S", "D"]);