Jump to content

Issue with image dragging


caiser
 Share

Recommended Posts

Hello guys,

I was following this tutorial (http://www.emanueleferonato.com/2015/01/21/create-an-html5-level-selection-screen-using-a-scrollable-map-like-in-hero-emblems-game-using-phaser/) and everything worked fine on Phaser 2.2.2.

But When I upgraded to Phaser 2.4.4, a bug has appeared: When you click on the map. you can start dragging it, but when you release the map it is still in drag mode (ie the dragging can't be stopped).

Any ideas on why is that ? Did something related to this change in 2.4.4 ? Could it be something related to scaling ?

Link to comment
Share on other sites

Hi, I am currently dragging map in my game. I use this:

        // -------------------------------------------------------------------------
        public onInputDown(pointer: Phaser.Pointer): void {
            this._oldCamera.setTo(pointer.position.x, pointer.position.y);
        }

        // -------------------------------------------------------------------------
        public onInputUp(pointer: Phaser.Pointer): void {
            this._oldCamera.setTo(-1, -1);
        }

        // -------------------------------------------------------------------------
        public onMapMoved(pointer: Phaser.Pointer, x: number, y: number, fromClick: boolean): void {
            if (!pointer.timeDown) {
                return;
            }

            if (pointer.isDown && this._oldCamera.x !== -1 && this._oldCamera.y !== -1) {

                var diffX = pointer.position.x - this._oldCamera.x;
                var diffY = pointer.position.y - this._oldCamera.y;

                this.game.camera.x -= diffX;
                this.game.camera.y -= diffY;

                this._oldCamera.setTo(pointer.position.x, pointer.position.y);
            }
        }

 which needs variable:

private _oldCamera: Phaser.Point = new Phaser.Point();

 and is initialized as:

            this.input.onDown.add(this.onInputDown, this);
            this.input.onUp.add(this.onInputUp, this);
            this.input.addMoveCallback(this.onMapMoved, this);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...