diff options
author | root <bryan@olenepal.org> | 2009-09-04 11:44:02 (GMT) |
---|---|---|
committer | root <bryan@olenepal.org> | 2009-09-04 11:44:02 (GMT) |
commit | 0d38359f8bda4d3584ea5042f8d59d49ac1ad827 (patch) | |
tree | 2712bfd51be258e4350ce0e58aad76fd59429883 | |
parent | 28eb6aab6ee0018d962f0403d702e0db6f653ba8 (diff) |
fixed bugs in jquery.karma.js , one that added the canvas element even if it was already present, and one in k.layer[].clear that cleared the width and the height only by the width
-rwxr-xr-x[-rw-r--r--] | examples/adding_up_to_10/assets/generic/images/balloon37px.png | bin | 2020 -> 2020 bytes | |||
-rwxr-xr-x[-rw-r--r--] | examples/adding_up_to_10/assets/generic/images/fish64px.png | bin | 2515 -> 2515 bytes | |||
-rwxr-xr-x[-rw-r--r--] | examples/adding_up_to_10/assets/generic/images/flower37px.png | bin | 2957 -> 2957 bytes | |||
-rwxr-xr-x | examples/adding_up_to_10/index.html | 6 | ||||
-rwxr-xr-x[-rw-r--r--] | examples/adding_up_to_10/index_multiple.html | 0 | ||||
-rwxr-xr-x | examples/adding_up_to_10/js/lesson.js | 101 | ||||
-rwxr-xr-x[-rw-r--r--] | examples/adding_up_to_10/js/lesson_multiple.js | 5 | ||||
-rwxr-xr-x | js/jquery.karma.js | 4 |
8 files changed, 64 insertions, 52 deletions
diff --git a/examples/adding_up_to_10/assets/generic/images/balloon37px.png b/examples/adding_up_to_10/assets/generic/images/balloon37px.png Binary files differindex 8f47d6a..8f47d6a 100644..100755 --- a/examples/adding_up_to_10/assets/generic/images/balloon37px.png +++ b/examples/adding_up_to_10/assets/generic/images/balloon37px.png diff --git a/examples/adding_up_to_10/assets/generic/images/fish64px.png b/examples/adding_up_to_10/assets/generic/images/fish64px.png Binary files differindex a29f12c..a29f12c 100644..100755 --- a/examples/adding_up_to_10/assets/generic/images/fish64px.png +++ b/examples/adding_up_to_10/assets/generic/images/fish64px.png diff --git a/examples/adding_up_to_10/assets/generic/images/flower37px.png b/examples/adding_up_to_10/assets/generic/images/flower37px.png Binary files differindex 224e707..224e707 100644..100755 --- a/examples/adding_up_to_10/assets/generic/images/flower37px.png +++ b/examples/adding_up_to_10/assets/generic/images/flower37px.png diff --git a/examples/adding_up_to_10/index.html b/examples/adding_up_to_10/index.html index 841e80a..23d0ab9 100755 --- a/examples/adding_up_to_10/index.html +++ b/examples/adding_up_to_10/index.html @@ -16,7 +16,7 @@ </head> <body> - <div id="main"> + <div id="karma-main"> <div id="action"> <div id="actionTop"> @@ -56,9 +56,7 @@ <div id="sidebar"> <div class="sidebarItem"> <img id="timer" src="assets/generic/images/scorebox.png" alt=""/> - <canvas id="timerCanvas" width="100" height="140" /> - <img id="banana" src="assets/generic/images/banana.png" alt=""/> - <img id="ball" src="assets/generic/images/ball.png" alt=""/> + <canvas id="timerCanvas" width="100" height="140" > </canvas> </div> <div class="sidebarItem"> <img id="scorebox" src="assets/generic/images/scorebox.png" alt=""/> diff --git a/examples/adding_up_to_10/index_multiple.html b/examples/adding_up_to_10/index_multiple.html index 15e5caa..15e5caa 100644..100755 --- a/examples/adding_up_to_10/index_multiple.html +++ b/examples/adding_up_to_10/index_multiple.html diff --git a/examples/adding_up_to_10/js/lesson.js b/examples/adding_up_to_10/js/lesson.js index c3dc400..e6697f6 100755 --- a/examples/adding_up_to_10/js/lesson.js +++ b/examples/adding_up_to_10/js/lesson.js @@ -1,6 +1,16 @@ $(document).ready(function(){ var k = $.karma ({container: "#karma-main", lang: "es-MX"}); + +/* k.layer( {id:"topLt", canvas:"topLtCanvas"} ); + k.layer( {id:"topRt", canvas:"topRtCanvas"} ); + k.layer( {id:"bottomLt", canvas:"bottomLtCanvas"} ); + k.layer( {id:"bottomMd", canvas:"bottomMdCanvas"} ); + k.layer( {id:"bottomRt", canvas:"bottomRtCanvas"} );*/ + k.layer( {id:"timer", canvas:"timerCanvas", width:"100", height:"140"} ); +// k.layer( {id:"scorebox", canvas:"scoreboxCanvas"} ); +// k.layer( {id:"chimp", canvas:"chimpCanvas"} ); + k.init({ images: [ {id: "ball", file: "ball37px.png", localized : false }, @@ -35,8 +45,8 @@ k.main(function() { var bottomRtCtx = bottomRtCanvas.getContext('2d'); var scoreboxCanvas = document.getElementById('scoreboxCanvas'); var scoreboxCtx = scoreboxCanvas.getContext('2d'); - var timerCanvas = document.getElementById('timerCanvas'); - var timerCtx = timerCanvas.getContext('2d'); +// var timerCanvas = document.getElementById('timerCanvas'); +// var timerCtx = timerCanvas.getContext('2d'); var actionContexts = [ topLtCtx, topRtCtx, bottomLtCtx, bottomMdCtx, bottomRtCtx]; @@ -54,36 +64,32 @@ k.main(function() { var endTimerX = 80; var startTimerY = 10; var endTimerY = 100; - var offsetTimerY = 20; + var offsetTimerY = 20; var timerId; var timerFn = function () { - timerCanvas.setAttribute("width", "100%"); - timerCtx.fillStyle = "#fff"; - timerCtx.fillRect(10, startTimerY, endTimerX, offsetTimerY); + k.layers['timer'].clear(); + k.layers['timer'].ctx.fillStyle = '#fff'; + k.layers['timer'].ctx.fillRect(10, startTimerY, endTimerX, offsetTimerY); +// timerCanvas.setAttribute("width", "100%"); +// timerCtx.fillStyle = "#fff"; +// timerCtx.fillRect(10, startTimerY, endTimerX, offsetTimerY); if ( startTimerY >= endTimerY ){ //make trigger sound - //answer(false); - + answer(false); game(); } else { - timerCanvas.setAttribute("width", "100%"); +// timerCanvas.setAttribute("width", "100%"); + k.layers['timer'].clear(); startTimerY = startTimerY + offsetTimerY; - timerCtx.fillStyle = "#fff"; - timerCtx.fillRect(10, startTimerY, endTimerX, offsetTimerY); + //timerCtx.fillStyle = "#fff"; + k.layers['timer'].ctx.fillStyle = "#fff"; + //timerCtx.fillRect(10, startTimerY, endTimerX, offsetTimerY); + k.layers['timer'].ctx.fillRect(10, startTimerY, endTimerX, offsetTimerY); } }; -/* var resetTimer = function () { - timerCanvas.setAttribute("width", "100%"); - startTimerY = 10; - timerCtx.fillStyle = "#fff"; - timerCtx.fillRect(1000, startTimerY, endTimerX, offsetTimerY); - timerId = setInterval (timerFn, 1200); - }; -*/ - function game () { $.each(actionContexts, function () { @@ -145,9 +151,7 @@ k.main(function() { card(bottomLtCtx, choices[ 0 ] , 0, 0, d); card(bottomMdCtx, choices[ 1 ] , 0, 0, d); card(bottomRtCtx, choices[ 2 ] , 0, 0, d); - if (!timerId){ - timerId = setInterval (timerFn, 1200); - } + timerId = setInterval (timerFn, 1200); } @@ -162,21 +166,37 @@ k.main(function() { var answer = function (correct) { if ( correct === false) { - // stop timer - //decrement score - //draw score + //answer was incorrect or took too long + clearInterval(timerId); + startTimerY = 10; + score = score - 1; + writeScore(); + k.library.sounds[ "incorrect" ].play(); //animate sad monkey - //say u got it wrong - //freezeTimer } else { - //stop timer - //increment score - + //answer was correct + clearInterval(timerId); + startTimerY = 10; + score = score + 1; + writeScore(); + k.library.sounds[ "correct" ].play(); + //animate happy monkey + level = (level+1)% imgNames.length; + } }; +/* var reset = function () { + score = 0; + startTimerY = 10; + $.each( ); + + + }; +*/ + writeScore(); //put the buttons var buttons=[]; @@ -187,21 +207,10 @@ k.main(function() { $.each(buttons, function( key, item ) { item.canvas.addEventListener('click', function( ev ) { if ( choices[ item.id ] === total){ - clearInterval(timerId); - score = score + 1; - writeScore(); - k.library.sounds[ "correct" ].play(); - //animateMonkey(true); - level = (level+1)% imgNames.length; - - }else { - clearInterval(timerId); - score = score - 1; - writeScore(); - k.library.sounds[ "incorrect" ].play(); - //animateMonkey(false); - } - game(); + answer(true); + }else { answer(false); } + + game(); }, true); }); game(); diff --git a/examples/adding_up_to_10/js/lesson_multiple.js b/examples/adding_up_to_10/js/lesson_multiple.js index d1361ff..572af44 100644..100755 --- a/examples/adding_up_to_10/js/lesson_multiple.js +++ b/examples/adding_up_to_10/js/lesson_multiple.js @@ -37,6 +37,11 @@ k.main(function() { "click", function(){layers["inline2"].clear();} ); + layers["inline2"].ctx.fillStyle = "#000"; + layers["inline2"].ctx.fillRect(0, 0, 150, 150); + layers["card2"].ctx.fillStyle = "#000"; + layers["card2"].ctx.fillRect(0, 0, 150, 150); + }); });
\ No newline at end of file diff --git a/js/jquery.karma.js b/js/jquery.karma.js index 04cca5a..4d95acf 100755 --- a/js/jquery.karma.js +++ b/js/jquery.karma.js @@ -633,7 +633,7 @@ var KLayer = Class( this.canvas.id = this.id; if ( this.canvas.getContext ) { this.ctx = this.canvas.getContext("2d"); - this.container.appendChild( this.canvas ); + //this.container.appendChild( this.canvas ); }else { throw new Error ("Your browser doesn't support canvas, \ try the newest Firefox, Safari or Google Chrome"); @@ -680,7 +680,7 @@ var KLayer = Class( x || 0, y || 0, width || this.canvas.width, - height || this.canvas.width + height || this.canvas.height ); }, draw: function ( ) { |