reduce update packets sent

This commit is contained in:
Asraelite 2016-03-30 12:50:59 +01:00
parent d6daed2e9b
commit ef2d067b38
15 changed files with 67 additions and 14 deletions

View file

@ -41,6 +41,8 @@ class Body {
type: 'body',
fixtures: this.mounts.length
};
this.sleepTime = 0;
}
destruct() {
@ -88,6 +90,8 @@ class Body {
if(pos.y < bounds.top) this.applyForce(0, 0.03);
if(pos.y > bounds.bottom) this.applyForce(-0, -0.03);
this.sleepTime++;
this.tickType();
}
@ -135,6 +139,15 @@ class Body {
return {};
}
get awake() {
if (this.b2body.IsAwake()) {
this.sleepTime = 0;
return true;
} else {
return this.sleepTime < 50;
}
}
get com() {
return {
x: this.b2body.GetLocalCenter().x,