Created
March 29, 2016 14:40
-
-
Save AlexBezuska/6f58ab8319af8c7b6fce to your computer and use it in GitHub Desktop.
Splat-ecs crop game render system, (letterboxing both directions)
This file contains 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
"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 | |
); | |
}, "background"); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment