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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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