Jump to content

Scroll left/right/up/down using mouse pointer


Recommended Posts

So I implemented this piece of code that scrolls around (up/down/left/right) using the mouse pointer. I basically have a map and I am scrolling to see areas that I don't normally see because the canvas size is much smaller than the map itself and that's how I want it since you can zoom in/out too.


What do you think about my code and what would you change and how can I make it better?

            //in create()            this.currentX = this.game.input.activePointer.x;             this.currentY = this.game.input.activePointer.y;             //in update()            if(this.game.input.activePointer.isDown && this.game.input.activePointer.x>this.currentX){              this.game.camera.x -= 8;              this.currentX = this.game.input.activePointer.x;            }            if(this.game.input.activePointer.isDown && this.game.input.activePointer.x<this.currentX){              this.game.camera.x += 8;              this.currentX = this.game.input.activePointer.x;            }            if(this.game.input.activePointer.isDown && this.game.input.activePointer.y>this.currentY){              this.game.camera.y -= 8;              this.currentY = this.game.input.activePointer.y;            }            if(this.game.input.activePointer.isDown && this.game.input.activePointer.y<this.currentY){              this.game.camera.y += 8;              this.currentY = this.game.input.activePointer.y;            }
Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...

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.

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.


  • Recently Browsing   0 members

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