From 01f7fabd6c03dbc4242b254a783591c1b5629d12 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Fri, 5 Jun 2015 17:15:59 +0200 Subject: [PATCH] Corrected coin counter Clicking on it will work when trying to click on a red coin or arrow --- js/prototype/Coin.js | 30 +++++++++++++++++++++++++----- js/prototype/main.js | 2 +- js/prototype/raycasterTools.js | 4 ++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/js/prototype/Coin.js b/js/prototype/Coin.js index 1865d69..d560e7a 100644 --- a/js/prototype/Coin.js +++ b/js/prototype/Coin.js @@ -13,24 +13,44 @@ Coin.extension = _toto.canPlayType("audio/x-vorbis") === "" ? ".ogg" : ".mp3"; Coin.domElement = document.createElement('canvas'); Coin.domElement.style.position = 'absolute'; -// Coin.domElement.style.cssFloat = 'top-right'; +Coin.domElement.style.cssFloat = 'top-left'; Coin.domElement.style.top = "0px"; -Coin.domElement.style.right = "0px"; +Coin.domElement.style.left = "0px"; Coin.image = new Image(); Coin.image.src = '/static/img/redcoin.png'; +Coin.initSize = function() { + try { + Coin.domElement.width = container_size.width(); + Coin.domElement.height = container_size.height(); + } catch (e) { + setTimeout(100, Coin.initSize); + return; + } +} + Coin.update = function() { + + var x; + try { + x = container_size.width() * 4.25 / 5; + Coin.domElement.width = container_size.width(); + Coin.domElement.height = container_size.height(); + } catch (e) { + return; + } + Coin.domElement.width = Coin.domElement.width; - Coin.ctx.drawImage(Coin.image,200,25,30,30); + Coin.ctx.drawImage(Coin.image, x + 75,25,30,30); Coin.ctx.fillStyle = 'red'; Coin.ctx.strokeStyle = 'black'; Coin.ctx.font = "30px Verdana"; - Coin.ctx.fillText(Coin.total - 1 + " / " + 8, 125, 50); - Coin.ctx.strokeText(Coin.total - 1 + " / " + 8, 125, 50); + Coin.ctx.fillText(Coin.total - 1 + " / " + 8, x, 50); + Coin.ctx.strokeText(Coin.total - 1 + " / " + 8, x, 50); Coin.ctx.fill(); Coin.ctx.stroke(); diff --git a/js/prototype/main.js b/js/prototype/main.js index ce36dab..a9b413b 100644 --- a/js/prototype/main.js +++ b/js/prototype/main.js @@ -73,8 +73,8 @@ function init() { // Add elements to page container.appendChild( stats.domElement ); container.appendChild(previewer.domElement); - container.appendChild(renderer.domElement); container.appendChild(Coin.domElement); + container.appendChild(renderer.domElement); // Initialize pointer camera var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.1, 100000, renderer, container); diff --git a/js/prototype/raycasterTools.js b/js/prototype/raycasterTools.js index 22ae286..c59268f 100644 --- a/js/prototype/raycasterTools.js +++ b/js/prototype/raycasterTools.js @@ -64,7 +64,7 @@ CameraSelecter.prototype.update = function(event) { } var previousCamera = this.currentPointedCamera; - var hovered = this.pointedCamera(event); + var hovered = this.pointedCamera(); if (hovered !== undefined && !(hovered instanceof Coin)) { if (hovered !== previousCamera) { @@ -92,7 +92,7 @@ CameraSelecter.prototype.update = function(event) { } CameraSelecter.prototype.click = function(event) { - var newCamera = this.pointedCamera(event); + var newCamera = this.pointedCamera(); if (newCamera !== undefined && !(newCamera instanceof Coin)) { var event = new BD.Event.ArrowClicked(); event.arrow_id = this.cameras.cameras.indexOf(newCamera);