From 2c1fc87836f70feed5f60fdb79b89c4d30b9cacc Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sun, 28 Sep 2014 19:17:30 +0200 Subject: Changed scale in HUD to relate better to game scale --- game/entities/hud.js | 71 ++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 36 deletions(-) (limited to 'game/entities/hud.js') diff --git a/game/entities/hud.js b/game/entities/hud.js index 43e7a21..bc4b466 100644 --- a/game/entities/hud.js +++ b/game/entities/hud.js @@ -1,48 +1,47 @@ 'use strict'; var Hud = function(game, player, x, y, scorefontKey, keyboardSpriteKey) { - Phaser.Group.call(this, game); - this.x = x; - this.y = y; - this.player = player; - this.scale = {x: 0.02, y: 0.02}; - - this.background = new Phaser.Sprite(this.game, 0, 0, 'hud-bg'); - this.add(this.background); - this.scoreText = new Phaser.BitmapText(this.game, 172, 10, scorefontKey, '0', 100); - this.add(this.scoreText); - - this.poisonIndicator = new Phaser.Sprite(this.game, 200, 150, 'poison-pill'); - this.poisonIndicator.anchor = {x:0.5, y:0.5}; - this.add(this.poisonIndicator); - - this.controllerDiagram = new Phaser.Sprite(this.game, 0, 300, 'controller-diagram'); - this.controllerDiagram.scale = {x: 0.5, y: 0.5}; - this.add(this.controllerDiagram); - - this.keyboardControls = new Phaser.Sprite(this.game, 0, 600, keyboardSpriteKey); - this.keyboardControls.scale = {x: 0.5, y: 0.5}; - this.add(this.keyboardControls); - - this.currentScore = 0; + Phaser.Group.call(this, game); + this.x = x; + this.y = y; + this.player = player; + this.scale = {x: 0.01, y: 0.01}; + + this.background = new Phaser.Sprite(this.game, 0, 0, 'hud-bg'); + this.add(this.background); + this.scoreText = new Phaser.BitmapText(this.game, 344, 20, scorefontKey, '0', 200); + this.add(this.scoreText); + + this.poisonIndicator = new Phaser.Sprite(this.game, 400, 300, 'poison-pill'); + this.poisonIndicator.scale = {x: 2, y: 2}; //bigger than an actual poison pill + this.poisonIndicator.anchor = {x: 0.5, y: 0.5}; + this.add(this.poisonIndicator); + + this.controllerDiagram = new Phaser.Sprite(this.game, 0, 600, 'controller-diagram'); + this.add(this.controllerDiagram); + + this.keyboardControls = new Phaser.Sprite(this.game, 0, 1200, keyboardSpriteKey); + this.add(this.keyboardControls); + + this.currentScore = 0; }; Hud.prototype = Object.create(Phaser.Group.prototype); Hud.prototype.constructor = Hud; Hud.prototype.update = function() { - if (this.currentScore !== this.player.score) { - this.currentScore = this.player.score; - this.scoreText.setText(this.player.score+''); - - var numberOfDigits = Math.floor(Math.log(this.currentScore)/Math.log(10))+1; - this.scoreText.x = 200 - numberOfDigits*30; - } - - if (this.poisonIndicator && !this.player.hasPoisonPill) { - this.poisonIndicator.destroy(); - this.poisonIndicator = null; - } + if (this.currentScore !== this.player.score) { + this.currentScore = this.player.score; + this.scoreText.setText(this.player.score+''); + + var numberOfDigits = Math.floor(Math.log(this.currentScore)/Math.log(10))+1; + this.scoreText.x = 400 - numberOfDigits*60; + } + + if (this.poisonIndicator && !this.player.hasPoisonPill) { + this.poisonIndicator.destroy(); + this.poisonIndicator = null; + } }; module.exports = Hud; -- cgit v1.2.3