cull body rendering

This commit is contained in:
Asraelite 2016-07-11 15:50:24 +02:00
parent c6021f798c
commit a7b4bd023d
2 changed files with 14 additions and 1 deletions

View file

@ -13,6 +13,18 @@ class BodyRenderer {
let pallet = this.pallet;
let context = pallet.context;
let limits = {
left: game.world.center.x - pallet.canvas.width / 2 - 100,
right: game.world.center.x + pallet.canvas.width / 2 + 100,
top: game.world.center.y - pallet.canvas.height / 2 - 100,
bottom: game.world.center.y + pallet.canvas.height / 2 + 100
};
if (x > limits.right || x < limits.left ||
y > limits.bottom || y < limits.top) {
return;
}
pallet.view(x, y, false, pos.r);
for (let f of body.fixtures) {

View file

@ -91,12 +91,13 @@ class Renderer {
let gridy = cy % 50;
let lastBlue = false;
let b = game.world.bounds;
this.pallet.opacity(0.05);
for (var x = gridx - cw / 2 - 50; x < cw + 50; x += 50) {
for (var y = gridy - ch / 2 - 50; y < ch + 50; y += 50) {
var wx = ((-cx + x) / SCALE) | 0;
var wy = ((-cy + y) / SCALE) | 0;
var b = game.world.bounds;
if (wx > b.right || wx < b.left || wy > b.bottom || wy < b.top) {
if (!lastBlue) {
this.pallet.opacity(0.2);