Jump to content

Callback for camera movement?


Sanic
 Share

Recommended Posts

Hey there,

Several places in my code change the position of the camera. There's character following, shaking, manual camera moving, etc.

I've overlaid a grid that matches the tile size of my tilemap and I'd like to update the position of the grid when the camera moves so it moves with the camera. I have a large tilemap so I'd rather not put a massive grid over it if I can help it... so I'll just reposition one the size of the screen when appropriate. I only need to do this when the camera moves... is there a way I can know when this has happened?

Link to comment
Share on other sites

Why not just add your own move method to the camera which also updates everything else you need and use that method instead of directly moving the camera?

myCamera.doMoveCamera = function(self, x, y) {
  calculateGameGrid(x, y);
  self.setPosition(x, y);
}

And in your code never call "myCamera.setPosition(...)", but alwas "myCamera.doMoveCamera(...)". I'm not sure how you're going to call the function, so I included a "self"

 

If that's too simplistic for you needs, you might also have a read on variable watching in various browsers, like e. g. this article.

Link to comment
Share on other sites

Thanks waechtertroll. That's my plan B... if it were just my code changing the camera that's all I'd need to do, but since I want to utilize game.camera.shake and game.camera.follow I'd need to account for the camera movements those make as well...

I was trying to get Object.observe to work, but it turns out it's depreciated, lol. I'd have to switch to FireFox to get Object.prototype.watch to work, and I can't work out how to use the last example... .___.;

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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