Jump to content

Scroll left/right/up/down using mouse pointer


Batzi
 Share

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...
 Share

  • Recently Browsing   0 members

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