Hello Posted March 7, 2021 Share Posted March 7, 2021 Hello I am following the sandbox code from https://phaser.io/sandbox/edit/3 with fair amount of refractoring but it says this.physics is undefined, any help appreciated import Phaser from "phaser"; var player; var platforms; var cursors; var jumpButton; class PhaserProject extends Phaser.Scene{ constructor() { super(); } preload() { this.load.baseURL = "http://examples.phaser.io/assets/"; this.load.crossOrigin = "anonymous"; this.load.image("player", "sprites/phaser-dude.png"); this.load.image("platform", "sprites/platform.png"); } create() { player = this.add.sprite(100, 200, "player"); this.physics.arcade.enable(player); player.body.collideWorldBounds = true; player.body.gravity.y = 500; platforms = this.add.physicsGroup(); platforms.create(500, 150, "platform"); platforms.create(-200, 300, "platform"); platforms.create(400, 450, "platform"); platforms.setAll("body.immovable", true); cursors = this.input.keyboard.createCursorKeys(); jumpButton = this.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); } update() { this.physics.arcade.collide(player, platforms); player.body.velocity.x = 0; if (cursors.left.isDown) { player.body.velocity.x = -250; } else if (cursors.right.isDown) { player.body.velocity.x = 250; } if ( jumpButton.isDown && (player.body.onFloor() || player.body.touching.down) ) { player.body.velocity.y = -400; } } render() {} } const config = { type: Phaser.AUTO, default: 'impact', parent: "phaser-example", width: 800, height: 600, scene: PhaserProject, }; const game = new Phaser.Game(config); Link to comment Share on other sites More sharing options...
Recommended Posts