Created
August 8, 2015 23:28
-
-
Save anonymous/539fced7eb707f88a1ba to your computer and use it in GitHub Desktop.
Simple camera for ROT.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define a camera XY object | |
Game.camera = new XY(); | |
// game draw function: | |
Game.draw = function(xy) { | |
var entity = this.level.getEntityAt(xy); | |
var visual = entity.getVisual(); | |
this.display.draw(xy.x - this.camera.x, xy.y - this.camera.y, visual.ch, visual.fg, visual.bg); | |
}; | |
// to move the camera, pass it an XY. For example, the player's XY. | |
Game.updateCamera = function(xy) { | |
// pick an offset x and y that makes sense for your game. | |
// you could probably also implement a camera trap here if you wanted to get fancy | |
this.camera.x = xy.x - 8; | |
this.camera.y = xy.y - 8; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment