skip to Main Content

I would like the camera to move to a specific offSetX. Using the method "horizontalCamera.setScroll(800,0)" it moves instantly. How can I make it move with an animation?
P.S. I’m using phaser editor 2d

class GoNext extends UserComponent {

    constructor(gameObject) {
        super(gameObject);

        this.gameObject = gameObject;
        gameObject["__GoNext"] = this;

        /* START-USER-CTR-CODE */
        // Write your code here.
        /* END-USER-CTR-CODE */
    }

    /** @returns {GoNext} */
    static getComponent(gameObject) {
        return gameObject["__GoNext"];
    }

    /** @type {Phaser.GameObjects.Text} */
    gameObject;

    /* START-USER-CODE */
    awake() {
        let horizontalCamera
        this.gameObject.setInteractive().on("pointerdown", () => {
            horizontalCamera = this.scene.cameras.add(0, 0, 800, 600)
            horizontalCamera.setScroll(800, 0)
        });
    }
    // Write your code here.

    /* END-USER-CODE */
}

3

Answers


  1. This method was a little difficult for me.

    Login or Signup to reply.
  2. If you want to pan to a specific position, you can use the function pan link to the documentation

       // moves the camera to the position (800,0) in 1000 ms
       this.cameras.main.pan(800, 0, 1000);
    

    Check out this official demo, for a usable demo.

    Login or Signup to reply.
  3. Also, you can "tween" the camera.

    Something like this:

    this.add.tween({
        targets: this.cameras.main,
        scrollX: x,
        scrollY: y
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search