Skip to content

Commit

Permalink
move displayProgress to jaws.assets.displayProgress so you can custom…
Browse files Browse the repository at this point in the history
…ize your own loadingscreen.. also pretty up the default one!
  • Loading branch information
ippa committed Mar 5, 2013
1 parent d4021b7 commit 2a3b9bb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
25 changes: 25 additions & 0 deletions src/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 8 additions & 23 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
Expand All @@ -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)
Expand Down

0 comments on commit 2a3b9bb

Please sign in to comment.