Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2015 23:28
Show Gist options
  • Save anonymous/539fced7eb707f88a1ba to your computer and use it in GitHub Desktop.
Save anonymous/539fced7eb707f88a1ba to your computer and use it in GitHub Desktop.
Simple camera for ROT.js
// 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