I have been trying to move down my rocket game object in the following MainScene code, the other keyboard inputs- up, left, right, work as expected but the player refuses to move down:
import { Physics } from "phaser"
export default class MainScene extends Phaser.Scene {
private ship!: Phaser.Physics.Arcade.Image
private cursor!: Phaser.Types.Input.Keyboard.CursorKeys
constructor() {
super({ key: 'MainScene' })
}
create(){
//use camera module
this.cameras.main.setBounds(0, 0, 3392, 240)
this.physics.world.setBounds(0, 0, 3392, 240)
const map = this.make.tilemap({key: "map"})
const tileset = map.addTilesetImage('SuperMarioBros-World1-1', 'tiles1')
map.createLayer("World1", tileset, 0, 0)
this.ship = this.physics.add.image(400, 100, 'ship').
setAngle(90).setCollideWorldBounds(true)
this.cursor = this.input.keyboard.createCursorKeys()
//course section
//this.cameras.main.startFollow(this.ship, true, 0.08, 0.08)
this.cameras.main.setZoom(4)
}
update(){
this.ship.setVelocity(0)
if (this.cursor.left?.isDown){
this.ship.setAngle(-90).setVelocityX(-200)
}
if (this.cursor.right?.isDown){
this.ship.setAngle(90).setVelocityX(200)
}
if (this.cursor.up?.isDown){
this.ship.setAngle(0).setVelocityY(-200)
}
if (this.cursor.down?.isDown){
this.ship.setAngle(-180).setVelocityX(200)
}
}
}
You can find the full project at: