cull body rendering
This commit is contained in:
parent
c6021f798c
commit
a7b4bd023d
2 changed files with 14 additions and 1 deletions
|
@ -13,6 +13,18 @@ class BodyRenderer {
|
||||||
let pallet = this.pallet;
|
let pallet = this.pallet;
|
||||||
let context = pallet.context;
|
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);
|
pallet.view(x, y, false, pos.r);
|
||||||
|
|
||||||
for (let f of body.fixtures) {
|
for (let f of body.fixtures) {
|
||||||
|
|
|
@ -91,12 +91,13 @@ class Renderer {
|
||||||
let gridy = cy % 50;
|
let gridy = cy % 50;
|
||||||
let lastBlue = false;
|
let lastBlue = false;
|
||||||
|
|
||||||
|
let b = game.world.bounds;
|
||||||
|
|
||||||
this.pallet.opacity(0.05);
|
this.pallet.opacity(0.05);
|
||||||
for (var x = gridx - cw / 2 - 50; x < cw + 50; x += 50) {
|
for (var x = gridx - cw / 2 - 50; x < cw + 50; x += 50) {
|
||||||
for (var y = gridy - ch / 2 - 50; y < ch + 50; y += 50) {
|
for (var y = gridy - ch / 2 - 50; y < ch + 50; y += 50) {
|
||||||
var wx = ((-cx + x) / SCALE) | 0;
|
var wx = ((-cx + x) / SCALE) | 0;
|
||||||
var wy = ((-cy + y) / 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 (wx > b.right || wx < b.left || wy > b.bottom || wy < b.top) {
|
||||||
if (!lastBlue) {
|
if (!lastBlue) {
|
||||||
this.pallet.opacity(0.2);
|
this.pallet.opacity(0.2);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue