Skip to content

Commit 1077f8e

Browse files
Merge pull request corehtml5canvas#7 from HakonD/master
Fixed Date bug (Chrome, IE) and label bug (FF)
2 parents 79785ad + d7b1b72 commit 1077f8e

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

ch07/example-7.3/example.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ var canvas = document.getElementById('canvas'),
3535
launchVelocityOutput = document.getElementById('launchVelocityOutput'),
3636
launchAngleOutput = document.getElementById('launchAngleOutput'),
3737

38-
elapsedTime = undefined,
3938
launchTime = undefined,
4039

4140
score = 0,
@@ -129,6 +128,7 @@ var canvas = document.getElementById('canvas'),
129128
elapsedFlightTime;
130129

131130
if (ballInFlight) {
131+
if (launchTime === undefined) launchTime = time;
132132
elapsedFrameTime = (time - this.lastTime)/1000,
133133
elapsedFlightTime = (time - launchTime)/1000;
134134

@@ -158,7 +158,7 @@ var canvas = document.getElementById('canvas'),
158158
else lastScore = 2;
159159

160160
score += lastScore;
161-
scoreboard.innerText = score;
161+
scoreboard.innerHTML = score;
162162
},
163163

164164
execute: function (bucket, context, time) {
@@ -266,7 +266,7 @@ canvas.onmousedown = function(e) {
266266
ball.velocityY = launchVelocity * Math.sin(launchAngle);
267267
ballInFlight = true;
268268
threePointer = false;
269-
launchTime = +new Date();
269+
launchTime = undefined;
270270
}
271271
};
272272

@@ -286,15 +286,14 @@ canvas.onmousemove = function (e) {
286286
launchAngle = Math.atan(parseFloat(deltaY) / parseFloat(deltaX));
287287
launchVelocity = 4 * deltaY / Math.sin(launchAngle) / pixelsPerMeter;
288288

289-
launchVelocityOutput.innerText = launchVelocity.toFixed(2);
290-
launchAngleOutput.innerText = (launchAngle * 180/Math.PI).toFixed(2);
289+
launchVelocityOutput.innerHTML = launchVelocity.toFixed(2);
290+
launchAngleOutput.innerHTML = (launchAngle * 180/Math.PI).toFixed(2);
291291
}
292292
};
293293

294294
// Animation Loop................................................
295295

296296
function animate(time) {
297-
elapsedTime = (time - launchTime) / 1000;
298297
context.clearRect(0,0,canvas.width,canvas.height);
299298

300299
if (!ballInFlight) {

0 commit comments

Comments
 (0)