Batzi Posted October 26, 2015 Share Posted October 26, 2015 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 More sharing options...
jmp909 Posted October 26, 2015 Share Posted October 26, 2015 tween to the pointer maybe? Link to comment Share on other sites More sharing options...
Batzi Posted October 26, 2015 Author Share Posted October 26, 2015 tween to the pointer maybe?what do you mean? Link to comment Share on other sites More sharing options...
jmp909 Posted October 26, 2015 Share Posted October 26, 2015 well you move the camera 8 pixels at a time, maybe you could move it smoothly to the pointer instead Link to comment Share on other sites More sharing options...
Batzi Posted October 26, 2015 Author Share Posted October 26, 2015 well you move the camera 8 pixels at a time, maybe you could move it smoothly to the pointer insteadGood point! Thanks, I will try that. Link to comment Share on other sites More sharing options...
jdnichollsc Posted October 28, 2015 Share Posted October 28, 2015 See my plugin: http://jdnichollsc.github.io/Phaser-Kinetic-Scrolling-Plugin/ Regards, Nicholls Link to comment Share on other sites More sharing options...
Batzi Posted November 19, 2015 Author Share Posted November 19, 2015 See my plugin: http://jdnichollsc.github.io/Phaser-Kinetic-Scrolling-Plugin/ Regards, NichollsDude you saved my life! Thank you!! jdnichollsc 1 Link to comment Share on other sites More sharing options...
jdnichollsc Posted December 10, 2015 Share Posted December 10, 2015 You can install my plugin using bower or npmbower i phaser-kinetic-scrolling-pluginRegards, Nicholls Batzi 1 Link to comment Share on other sites More sharing options...
Recommended Posts