From 2a3b9bb98574543ab47d2a6f017b3e592ef639e0 Mon Sep 17 00:00:00 2001 From: ippa Date: Tue, 5 Mar 2013 11:49:34 +0100 Subject: [PATCH] move displayProgress to jaws.assets.displayProgress so you can customize your own loadingscreen.. also pretty up the default one! --- src/assets.js | 25 +++++++++++++++++++++++++ src/core.js | 31 ++++++++----------------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/assets.js b/src/assets.js index 8005c83..f57e4ef 100755 --- a/src/assets.js +++ b/src/assets.js @@ -226,6 +226,31 @@ jaws.Assets = function Assets() { that.onfinish = null } } + this.displayProgress = function(percent_done) { + if(!jaws.context) return; + + jaws.context.save() + jaws.context.fillStyle = "black" + jaws.context.fillRect(0, 0, jaws.width, jaws.height) + + jaws.context.fillStyle = "white" + jaws.context.strokeStyle = "white" + jaws.context.textAlign = "center" + + jaws.context.strokeRect(50-1, (jaws.height/2)-30-1, jaws.width-100+2, 60+2) + jaws.context.fillRect(50, (jaws.height/2)-30, ((jaws.width-100)/100)*percent_done, 60) + + jaws.context.font = "11px verdana" + jaws.context.fillText("Loading game ... " + percent_done + "%", jaws.width/2, jaws.height/2-35) + + jaws.context.font = "11px verdana" + jaws.context.fillStyle = "#ccc" + jaws.context.textBaseline = "bottom" + jaws.context.fillText("powered by www.jawsjs.com", jaws.width/2, jaws.height-1) + + jaws.context.restore() + } + } /** @private diff --git a/src/core.js b/src/core.js index 71b9332..7e6ba1b 100755 --- a/src/core.js +++ b/src/core.js @@ -166,35 +166,20 @@ function saveMousePosition(e) { jaws.start = function(game_state, options,game_state_setup_options) { if(!options) options = {}; var fps = options.fps || 60 - if (options.loading_screen === undefined) - options.loading_screen = true - - if(!options.width) options.width = 500; - if(!options.height) options.height = 300; + if(options.loading_screen === undefined) options.loading_screen = true; + if(!options.width) options.width = 500; + if(!options.height) options.height = 300; jaws.init(options) - displayProgress(0) + if(options.loading_screen) { jaws.assets.displayProgress(0) } + jaws.log("setupInput()", true) jaws.setupInput() - function displayProgress(percent_done) { - if(jaws.context && options.loading_screen) { - jaws.context.save() - jaws.context.fillStyle = "black" - jaws.context.fillRect(0, 0, jaws.width, jaws.height); - jaws.context.textAlign = "center" - jaws.context.fillStyle = "white" - jaws.context.font = "15px terminal"; - jaws.context.fillText("Loading", jaws.width/2, jaws.height/2-30); - jaws.context.font = "bold 30px terminal"; - jaws.context.fillText(percent_done + "%", jaws.width/2, jaws.height/2); - jaws.context.restore() - } - } /* Callback for when one single assets has been loaded */ function assetLoaded(src, percent_done) { - jaws.log( percent_done + "%: " + src, true) - displayProgress(percent_done) + jaws.log(percent_done + "%: " + src, true) + if(options.loading_screen) { jaws.assets.displayProgress(percent_done) } } /* Callback for when an asset can't be loaded*/ @@ -205,7 +190,7 @@ jaws.start = function(game_state, options,game_state_setup_options) { /* Callback for when all assets are loaded */ function assetsLoaded() { jaws.log("all assets loaded", true) - jaws.switchGameState(game_state||window, {fps: fps},game_state_setup_options) + jaws.switchGameState(game_state||window, {fps: fps}, game_state_setup_options) } jaws.log("assets.loadAll()", true)