Skip to content

Instantly share code, notes, and snippets.

@AlexBezuska
Created April 16, 2016 23:09
Show Gist options
  • Save AlexBezuska/e5df878b31e7859f32e60ffee1664310 to your computer and use it in GitHub Desktop.
Save AlexBezuska/e5df878b31e7859f32e60ffee1664310 to your computer and use it in GitHub Desktop.
"use strict";
module.exports = function(ecs, game) { // eslint-disable-line no-unused-vars
ecs.addEach(function(entity, context) { // eslint-disable-line no-unused-vars
var viewportPosition = game.entities.get(entity, "position");
var viewportSize = game.entities.get(entity, "size");
var cameraPosition = game.entities.get(0, "position");
var cameraSize = game.entities.get(0, "size");
context.fillStyle = "black";
context.fillRect(
cameraPosition.x,
cameraPosition.y,
cameraSize.width,
viewportPosition.y - cameraPosition.y
);
context.fillRect(
viewportPosition.x + viewportSize.width,
cameraPosition.y,
cameraSize.width - (viewportPosition.x + viewportSize.width),
cameraSize.height
);
context.fillRect(
cameraPosition.x,
viewportPosition.y + viewportSize.height,
cameraSize.width,
cameraSize.height - (viewportPosition.y + viewportSize.height)
);
context.fillRect(
cameraPosition.x,
cameraPosition.y,
viewportPosition.x - cameraPosition.x,
cameraSize.height
);
}, "viewPort");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment