Jump to content

Moving camera using mouse cursor


levshkatov
 Share

Recommended Posts

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

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.

Link to comment
Share on other sites

  • 1 year later...
 Share

  • Recently Browsing   0 members

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