From f2bcc6f5b04d9567a7953b504369d84aef490a08 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Mon, 8 Jun 2015 20:19:28 +0200 Subject: [PATCH] Better scale calculation Had to take it from the client app, since the server clips the exact same. --- script.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/script.js b/script.js index 4c0794d..60fb962 100644 --- a/script.js +++ b/script.js @@ -209,6 +209,10 @@ function Viewer(client, container) { _this.addListners(); _this.addBorders(); _this.animate(); + _this.homeview = true; + client.once('myNewBall', function() { + _this.homeview = false; + }); _this.emit('launched'); }); window.addEventListener('resize', function () { @@ -232,13 +236,19 @@ Viewer.prototype = { this.getSize(); this.renderer.resize(this.width, this.height); }, + defaultScale: function () { + return Math.max(this.width / 1920, this.height / 1080) + }, initStage: function () { this.stage = new PIXI.Container(); this.cam = { x: new AnimatedValue(this.gameWidth / 2), y: new AnimatedValue(this.gameHeight / 2), - s: new AnimatedValue(0.5) + s: new AnimatedValue(this.defaultScale()) }; + this.d = {}; + this.dg = new PIXI.Graphics(); + this.stage.addChild(this.dg); }, addListners: function () { var _this = this; @@ -293,8 +303,9 @@ Viewer.prototype = { if (p > 0) { // if we have visible ball(s) this.cam.x.set(x / p, 100); this.cam.y.set(y / p, 100); - this.cam.s.set(0.04 * this.width / p, 500); // Scale - // TODO Better scale calculation + this.cam.s.set(Math.pow(Math.min(64 / p, 1), 0.4) * this.defaultScale(), 500); + } else if (this.homeview) { + this.cam.s.write(this.defaultScale()); } // else: don't move the camera }, render: function () {