Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eemeli Kelokorpi committed Mar 21, 2014
2 parents 6b872db + 0acde91 commit 44950bd
Show file tree
Hide file tree
Showing 18 changed files with 275 additions and 245 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DS_Store
game.min.js
game.cache
node_modules
plugins
editor
bamboo

bamboo
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<title>Panda.js HTML5 game engine</title>

<script type="text/javascript" src="src/game/config.js"></script>
Expand Down
Binary file added media/rotate.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 76 additions & 15 deletions src/engine/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ game.Audio = game.Class.extend({
this.sources[id].audio.playing = true;
if(typeof(callback) === 'function') this.sources[id].audio.onended = callback.bind(this);
else this.sources[id].audio.onended = null;
this.sources[id].audio.currentTime = 0;
this.sources[id].audio.play();
}
},
Expand All @@ -222,7 +223,8 @@ game.Audio = game.Class.extend({
}
// HTML5 Audio
else {
this.sources[id].audio.pause();
if(navigator.isCocoonJS) this.sources[id].audio.volume = 0;
else this.sources[id].audio.pause();
this.sources[id].audio.playing = false;
this.sources[id].audio.currentTime = 0;
}
Expand Down Expand Up @@ -255,6 +257,21 @@ game.Audio = game.Class.extend({
}
},

resume: function(id) {
if(!this.sources[id]) throw('Cannot find source: ' + id);

// Web Audio
if(this.context) {
if(this.sources[id].audio.pauseTime) {
this.play(id, this.sources[id].audio.volume, this.sources[id].audio.loop);
}
}
// HTML5 Audio
else {
if(this.sources[id].audio.playing) this.sources[id].audio.play();
}
},

/**
@method playSound
@param {String} id
Expand Down Expand Up @@ -283,7 +300,41 @@ game.Audio = game.Class.extend({
this.stop(id);
} else {
// Stop all sounds
for(var i in this.sources) this.stop(i);
for(id in this.sources) {
if(id !== this.currentMusic) this.stop(id);
}
}
},

/**
@method pauseSound
@param {String} [id]
**/
pauseSound: function(id) {
if(!game.Audio.enabled) return;

if(id) this.pause(id);
else {
// Pause all sounds
for(id in this.sources) {
if(id !== this.currentMusic) this.pause(id);
}
}
},

/**
@method resumeSound
@param {String} [id]
**/
resumeSound: function(id) {
if(!game.Audio.enabled) return;

if(id) this.resume(id);
else {
// Resume all sounds
for(id in this.sources) {
if(id !== this.currentMusic) this.resume(id);
}
}
},

Expand Down Expand Up @@ -315,16 +366,33 @@ game.Audio = game.Class.extend({
},

/**
@method pauseSound
@param {String} id
@method pauseMusic
**/
pauseSound: function(id) {
pauseMusic: function() {
if(!game.Audio.enabled) return;

this.pause(id);
if(this.currentMusic) this.pause(this.currentMusic);
},

/**
@method resumeMusic
**/
resumeMusic: function() {
if(!game.Audio.enabled) return;

if(this.currentMusic) {
if(this.context) {
// Web Audio
this.play(this.currentMusic);
} else {
// HTML5 Audio
if(this.sources[this.currentMusic].audio.playing) this.sources[this.currentMusic].audio.play();
}
}
},

/**
Pause all sounds and music
@method pauseAll
**/
pauseAll: function() {
Expand All @@ -334,20 +402,13 @@ game.Audio = game.Class.extend({
},

/**
Resume all sounds and music
@method resumeAll
**/
resumeAll: function() {
if(!game.Audio.enabled) return;

for(var id in this.sources) {
if(this.context) {
if(this.sources[id].audio.pauseTime) {
this.play(id, this.sources[id].audio.volume, this.sources[id].audio.loop);
}
} else {
if(this.sources[id].audio.playing) this.sources[id].audio.play();
}
}
for(var id in this.sources) this.resume(id);
},

// Deprecated
Expand Down
77 changes: 0 additions & 77 deletions src/engine/build.js

This file was deleted.

50 changes: 30 additions & 20 deletions src/engine/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if(typeof(global) !== 'undefined' && global.game) return;
@class Core
**/
var core = {
version: '1.1.6',
version: '1.2.0',
config: window.pandaConfig || {},
plugins: {},
json: {},
Expand Down Expand Up @@ -244,6 +244,7 @@ var core = {
**/
addAsset: function(path, id) {
id = id || path;
path = this.config.mediaFolder + path;
this.assets[id] = path;
if(this.resources.indexOf(path) === -1) this.resources.push(path);
return path;
Expand All @@ -260,19 +261,10 @@ var core = {
**/
addAudio: function(path, id) {
id = id || path;
path = this.config.mediaFolder + path;
game.Audio.queue[path] = id;
return id;
},

// Deprecated
addSound: function(path, id) {
this.addAudio(path, id);
},

// Deprecated
addMusic: function(path, id) {
this.addAudio(path, id);
},

setNocache: function() {
this.nocache = '?' + Date.now();
Expand Down Expand Up @@ -319,6 +311,7 @@ var core = {
this._current.body = body;
this._current = null;
if(this._initDOMReady) this._initDOMReady();
else if(this.loadFinished) this._loadModules();
},

/**
Expand All @@ -335,11 +328,7 @@ var core = {

this.system = new game.System(width, height, canvasId);

if(game.Audio) {
this.audio = new game.Audio();
this.sound = this.audio; // Deprecated
}

if(game.Audio) this.audio = new game.Audio();
if(game.Pool) this.pool = new game.Pool();
if(game.DebugDraw && game.DebugDraw.enabled) this.debugDraw = new game.DebugDraw();
if(game.Storage && game.Storage.id) this.storage = new game.Storage(game.Storage.id);
Expand Down Expand Up @@ -456,14 +445,14 @@ var core = {
unresolved.push(game._loadQueue[i].name + ' (requires: ' + unloaded.join(', ') + ')');
}
throw('Unresolved modules:\n' + unresolved.join('\n'));
} else {
this.loadFinished = true;
}
},

_boot: function() {
if(document.location.href.match(/\?nocache/)) this.setNocache();

this.config.sourceFolder = this.config.sourceFolder || 'src';

this.device.pixelRatio = window.devicePixelRatio || 1;
this.device.screen = {
width: window.screen.availWidth * this.device.pixelRatio,
Expand All @@ -481,6 +470,7 @@ var core = {
this.device.iOS5 = (this.device.iOS && /OS 5/i.test(navigator.userAgent));
this.device.iOS6 = (this.device.iOS && /OS 6/i.test(navigator.userAgent));
this.device.iOS7 = (this.device.iOS && /OS 7/i.test(navigator.userAgent));
this.device.iOS71 = (this.device.iOS && /OS 7_1/i.test(navigator.userAgent));

this.device.android = /android/i.test(navigator.userAgent);
this.device.android2 = /android 2/i.test(navigator.userAgent);
Expand Down Expand Up @@ -509,9 +499,29 @@ var core = {
};
}
}

var i;
if(this.device.iOS && this.config.iOS) {
for(i in this.config.iOS) this.config[i] = this.config.iOS[i];
}

if(this.device.android && this.config.android) {
for(i in this.config.android) this.config[i] = this.config.android[i];
}

// Deprecated
this.ua = this.device;
if(this.device.wp && this.config.wp) {
for(i in this.config.wp) this.config[i] = this.config.wp[i];
}

this.config.sourceFolder = this.config.sourceFolder || 'src';
this.config.mediaFolder = this.config.mediaFolder ? this.config.mediaFolder + '/' : '';

var viewport = document.createElement('meta');
viewport.name = 'viewport';
var content = 'width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no';
if(this.device.iOS71) content += ',minimal-ui';
viewport.content = content;
document.getElementsByTagName('head')[0].appendChild(viewport);
},

_DOMReady: function() {
Expand Down

0 comments on commit 44950bd

Please sign in to comment.