Sanic Posted December 5, 2016 Share Posted December 5, 2016 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 More sharing options...
waechtertroll Posted December 6, 2016 Share Posted December 6, 2016 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 More sharing options...
Sanic Posted December 6, 2016 Author Share Posted December 6, 2016 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 More sharing options...
samme Posted December 6, 2016 Share Posted December 6, 2016 Can you just monitor camera.view? Link to comment Share on other sites More sharing options...
samme Posted December 6, 2016 Share Posted December 6, 2016 Link to comment Share on other sites More sharing options...
Recommended Posts