Why this error ?How to rotate sprite?

Click on Example.js:28. What is it?


class Example extends Phaser.Scene {

  constructor(){

      super({key : "Example"});
  }
   
  preload(){
      this.load.image('ship','./assets/ship.png');
  }
  create(){
      this.add.image(50,40,'ship');
      this.cursors = this.input.keyboard.createCursorKeys();
  }
  update(){
    if (this.cursors.left.isDown)
    {
        this.ship.setScale();
    }
    else if (this.cursors.right.isDown)
    {
        this.ship.setAngularVelocity(0.1);
    }

    if (this.cursors.up.isDown)
    {
        this.ship.thrust(0.08);
    }
  }
}

Line 28 is probably

this.ship.thrust(0.08);

Error says

Cannot read property ‘thrust’ of undefined

so

(undefined).thrust(0.08);

so this.ship is undefined.

1 Like

Ok thanks ,i try to use arcade not matter I change to use it but i don’t understand what this code means
setDamping , setDrag ,…It works fine but not clear for me!