this.outerContainerEl = document.querySelector(outerContainerId);
this.containerEl = null;
+ this.detailsButton = this.outerContainerEl.querySelector('#details-button');
this.config = opt_config || Runner.config;
/** @const */
var IS_TOUCH_ENABLED = 'ontouchstart' in window;
+/** @const */
+var IS_IOS = window.navigator.userAgent.indexOf('CriOS') > -1;
/**
* Default game configuration.
* Load and decode base 64 encoded sounds.
*/
loadSounds: function() {
- this.audioContext = new AudioContext();
- var resourceTemplate =
- document.getElementById(this.config.RESOURCE_TEMPLATE_ID).content;
-
- for (var sound in Runner.sounds) {
- var soundSrc = resourceTemplate.getElementById(Runner.sounds[sound]).src;
- soundSrc = soundSrc.substr(soundSrc.indexOf(',') + 1);
- var buffer = decodeBase64ToArrayBuffer(soundSrc);
-
- // Async, so no guarantee of order in array.
- this.audioContext.decodeAudioData(buffer, function(index, audioData) {
- this.soundFx[index] = audioData;
- }.bind(this, sound));
+ if (!IS_IOS) {
+ this.audioContext = new AudioContext();
+ var resourceTemplate =
+ document.getElementById(this.config.RESOURCE_TEMPLATE_ID).content;
+
+ for (var sound in Runner.sounds) {
+ var soundSrc =
+ resourceTemplate.getElementById(Runner.sounds[sound]).src;
+ soundSrc = soundSrc.substr(soundSrc.indexOf(',') + 1);
+ var buffer = decodeBase64ToArrayBuffer(soundSrc);
+
+ // Async, so no guarantee of order in array.
+ this.audioContext.decodeAudioData(buffer, function(index, audioData) {
+ this.soundFx[index] = audioData;
+ }.bind(this, sound));
+ }
}
},
update: function() {
this.drawPending = false;
- var now = performance.now();
+ var now = getTimeStamp();
var deltaTime = now - (this.time || now);
this.time = now;
* @param {Event} e
*/
onKeyDown: function(e) {
- if (!this.crashed && (Runner.keycodes.JUMP[String(e.keyCode)] ||
- e.type == Runner.events.TOUCHSTART)) {
- if (!this.activated) {
- this.loadSounds();
- this.activated = true;
- }
+ if (e.target != this.detailsButton) {
+ if (!this.crashed && (Runner.keycodes.JUMP[String(e.keyCode)] ||
+ e.type == Runner.events.TOUCHSTART)) {
+ if (!this.activated) {
+ this.loadSounds();
+ this.activated = true;
+ }
- if (!this.tRex.jumping) {
- this.playSound(this.soundFx.BUTTON_PRESS);
- this.tRex.startJump();
+ if (!this.tRex.jumping) {
+ this.playSound(this.soundFx.BUTTON_PRESS);
+ this.tRex.startJump();
+ }
}
- }
- if (this.crashed && e.type == Runner.events.TOUCHSTART &&
- e.currentTarget == this.containerEl) {
- this.restart();
+ if (this.crashed && e.type == Runner.events.TOUCHSTART &&
+ e.currentTarget == this.containerEl) {
+ this.restart();
+ }
}
// Speed drop, activated only when jump key is not pressed.
this.tRex.speedDrop = false;
} else if (this.crashed) {
// Check that enough time has elapsed before allowing jump key to restart.
- var deltaTime = performance.now() - this.time;
+ var deltaTime = getTimeStamp() - this.time;
if (Runner.keycodes.RESTART[keyCode] ||
(e.type == Runner.events.MOUSEUP && e.target == this.canvas) ||
}
// Reset the time clock.
- this.time = performance.now();
+ this.time = getTimeStamp();
},
stop: function() {
this.activated = true;
this.paused = false;
this.tRex.update(0, Trex.status.RUNNING);
- this.time = performance.now();
+ this.time = getTimeStamp();
this.update();
}
},
this.distanceRan = 0;
this.setSpeed(this.config.SPEED);
- this.time = performance.now();
+ this.time = getTimeStamp();
this.containerEl.classList.remove(Runner.classes.CRASHED);
this.clearCanvas();
this.distanceMeter.reset(this.highestScore);
* @param {number} duration Duration of the vibration in milliseconds.
*/
function vibrate(duration) {
- if (IS_MOBILE) {
- window.navigator['vibrate'](duration);
+ if (IS_MOBILE && window.navigator.vibrate) {
+ window.navigator.vibrate(duration);
}
}
}
+/**
+ * Return the current timestamp.
+ * @return {number}
+ */
+function getTimeStamp() {
+ return IS_IOS ? new Date().getTime() : performance.now();
+}
+
+
//******************************************************************************
this.currentAnimFrames = Trex.animFrames[opt_status].frames;
if (opt_status == Trex.status.WAITING) {
- this.animStartTime = performance.now();
+ this.animStartTime = getTimeStamp();
this.setBlinkDelay();
}
}
}
if (this.status == Trex.status.WAITING) {
- this.blink(performance.now());
+ this.blink(getTimeStamp());
} else {
this.draw(this.currentAnimFrames[this.currentFrame], 0);
}
* @enum {number}
*/
Cloud.config = {
- HEIGHT: 13,
+ HEIGHT: 14,
MAX_CLOUD_GAP: 400,
MAX_SKY_LEVEL: 30,
MIN_CLOUD_GAP: 100,