levshkatov Posted October 20, 2015 Share Posted October 20, 2015 Ho to move camera using coordinates from mouse cursor? I tried to do it like that: function create () {coords.x = game.input.mousePointer.x;coords.y = game.input.mousePointer.y;}function update() { game.camera.x = ((window.innerWidth/2 - coords.x)/window.innerWidth)*1.5game.camera.y = ((window.innerHeight/2 - coords.y)/window.innerHeight)*1.5}But it doesn't work. (1.5 is velocity of camera) Link to comment Share on other sites More sharing options...
chongdashu Posted October 21, 2015 Share Posted October 21, 2015 Wouldn't you need coords.x and coords.y to be set in update() if the camera is to follow the mouse? Link to comment Share on other sites More sharing options...
Skeptron Posted October 21, 2015 Share Posted October 21, 2015 chongdashu is right : you need to update your camera's position in the update() function. The create() function is called only once, at game start, whereas the update() function is called 60 times per second (or so, regarding your FPS). If you want your camera to move real-time, you need to do it in the update() function. chongdashu 1 Link to comment Share on other sites More sharing options...
thamaluka Posted May 12, 2017 Share Posted May 12, 2017 if (this.game.input.activePointer.isDown) { this.game.camera.y -= this.game.input.mouse.event.movementY; this.game.camera.x -= this.game.input.mouse.event.movementX; } That's work for me! phaser 2.6.2 Link to comment Share on other sites More sharing options...
Recommended Posts