Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions CocosDenshion/SimpleAudioEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */
_maxAudioInstance:10,
_canPlay:true,
_musicListenerBound:null,
_musicIsStopped: false,

/**
* Constructor
Expand Down Expand Up @@ -277,6 +278,7 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */
au.loop = loop || false;
au.play();
cc.AudioEngine.isMusicPlaying = true;
this._musicIsStopped = false;
},

_musicListener:function(e){
Expand All @@ -300,10 +302,10 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */
var au = locSoundList[locPlayingMusic].audio;
au.pause();
au.currentTime = au.duration;
if (releaseData) {
if (releaseData)
delete locSoundList[locPlayingMusic];
}
cc.AudioEngine.isMusicPlaying = false;
this._musicIsStopped = true;
}
},

Expand All @@ -314,7 +316,7 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */
* cc.AudioEngine.getInstance().pauseMusic();
*/
pauseMusic:function () {
if (this._soundList.hasOwnProperty(this._playingMusic)) {
if (!this._musicIsStopped && this._soundList.hasOwnProperty(this._playingMusic)) {
var au = this._soundList[this._playingMusic].audio;
au.pause();
cc.AudioEngine.isMusicPlaying = false;
Expand All @@ -328,7 +330,7 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */
* cc.AudioEngine.getInstance().resumeMusic();
*/
resumeMusic:function () {
if (this._soundList.hasOwnProperty(this._playingMusic)) {
if (!this._musicIsStopped && this._soundList.hasOwnProperty(this._playingMusic)) {
var au = this._soundList[this._playingMusic].audio;
au.play();
au.addEventListener("pause", this._musicListenerBound , false);
Expand All @@ -349,6 +351,7 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */
au.play();
au.addEventListener("pause", this._musicListenerBound , false);
cc.AudioEngine.isMusicPlaying = true;
this._musicIsStopped = false;
}
},

Expand Down Expand Up @@ -715,6 +718,7 @@ cc.SimpleAudioEngineForMobile = cc.SimpleAudioEngine.extend({
au.loop = loop || false;
au.play();
cc.AudioEngine.isMusicPlaying = true;
this._musicIsStopped = false;
},

_musicListener:function(){
Expand Down Expand Up @@ -1818,7 +1822,7 @@ cc.AudioEngine.getInstance = function () {
if (cc.Browser.supportWebAudio && !(/iPhone OS/.test(ua)||/iPad/.test(ua))) {
this._instance = new cc.WebAudioEngine();
} else {
if(cc.Browser.isMobile) //TODO construct a supported list for mobile browser
if(cc.Browser.isMobile) // TODO construct a supported list for mobile browser
this._instance = new cc.SimpleAudioEngineForMobile();
else
this._instance = new cc.SimpleAudioEngine();
Expand Down
79 changes: 50 additions & 29 deletions cocos2d/platform/CCApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,62 +167,65 @@ cc.isAddedHiddenEvent = false;
*/
cc.setup = function (el, width, height) {
var element = cc.$(el) || cc.$('#' + el);
var localCanvas, localContainer, localConStyle;
if (element.tagName == "CANVAS") {
width = width || element.width;
height = height || element.height;

//it is already a canvas, we wrap it around with a div
cc.container = cc.$new("DIV");
cc.canvas = element;
cc.canvas.parentNode.insertBefore(cc.container, cc.canvas);
cc.canvas.appendTo(cc.container);
cc.container.style.width = (width || 480) + "px";
cc.container.style.height = (height || 320) + "px";
cc.container.setAttribute('id', 'Cocos2dGameContainer');
cc.container.style.margin = "0 auto";
cc.canvas.setAttribute("width", width || 480);
cc.canvas.setAttribute("height", height || 320);
localContainer = cc.container = cc.$new("DIV");
localConStyle = localContainer.style;
localCanvas = cc.canvas = element;
localCanvas.parentNode.insertBefore(localContainer, localCanvas);
localCanvas.appendTo(localContainer);
localConStyle.width = (width || 480) + "px";
localConStyle.height = (height || 320) + "px";
localContainer.setAttribute('id', 'Cocos2dGameContainer');
localConStyle.margin = "0 auto";
localCanvas.setAttribute("width", width || 480);
localCanvas.setAttribute("height", height || 320);
} else {//we must make a new canvas and place into this element
if (element.tagName != "DIV") {
cc.log("Warning: target element is not a DIV or CANVAS");
}
width = width || element.clientWidth;
height = height || element.clientHeight;

cc.canvas = cc.$new("CANVAS");
cc.canvas.addClass("gameCanvas");
cc.canvas.setAttribute("width", width || 480);
cc.canvas.setAttribute("height", height || 320);
cc.container = element;
element.appendChild(cc.canvas);
cc.container.style.width = (width || 480) + "px";
cc.container.style.height = (height || 320) + "px";
cc.container.style.margin = "0 auto";
localCanvas = cc.canvas = cc.$new("CANVAS");
localCanvas.addClass("gameCanvas");
localCanvas.setAttribute("width", width || 480);
localCanvas.setAttribute("height", height || 320);
localContainer = cc.container = element;
localConStyle = localContainer.style;
element.appendChild(localCanvas);
localConStyle.width = (width || 480) + "px";
localConStyle.height = (height || 320) + "px";
localConStyle.margin = "0 auto";
}
cc.container.style.position = 'relative';
cc.container.style.overflow = 'hidden';
cc.container.top = '100%';
localConStyle.position = 'relative';
localConStyle.overflow = 'hidden';
localContainer.top = '100%';

if(cc.__renderDoesnotSupport)
return;

if (cc.Browser.supportWebGL)
cc.renderContext = cc.webglContext = cc.create3DContext(cc.canvas,{'stencil': true, 'preserveDrawingBuffer': true, 'alpha': false });
cc.renderContext = cc.webglContext = cc.create3DContext(localCanvas,{'stencil': true, 'preserveDrawingBuffer': true, 'alpha': false });
if(cc.renderContext){
cc.renderContextType = cc.WEBGL;
window.gl = cc.renderContext; // global variable declared in CCMacro.js
cc.drawingUtil = new cc.DrawingPrimitiveWebGL(cc.renderContext);
cc.TextureCache.getInstance()._initializingRenderer();
} else {
cc.renderContext = cc.canvas.getContext("2d");
cc.renderContext = localCanvas.getContext("2d");
cc.mainRenderContextBackup = cc.renderContext;
cc.renderContextType = cc.CANVAS;
cc.renderContext.translate(0, cc.canvas.height);
cc.renderContext.translate(0, localCanvas.height);
cc.drawingUtil = new cc.DrawingPrimitiveCanvas(cc.renderContext);
}

cc.originalCanvasSize = cc.size(cc.canvas.width, cc.canvas.height);
cc.gameDiv = cc.container;
cc.originalCanvasSize = cc.size(localCanvas.width, localCanvas.height);
cc.gameDiv = localContainer;

cc.log(cc.ENGINE_VERSION);
cc.Configuration.getInstance();
Expand Down Expand Up @@ -250,13 +253,30 @@ cc.setup = function (el, width, height) {
}

function handleVisibilityChange() {
if (!document[hidden])
var audioEngine = cc.AudioEngine.getInstance();
if (!document[hidden]){
cc.Director.getInstance()._resetLastUpdate();
audioEngine.resumeAllEffects();
audioEngine.resumeMusic();
} else{
audioEngine.pauseAllEffects();
audioEngine.pauseMusic();
}
}

if (typeof document.addEventListener === "undefined" ||
typeof hidden === "undefined") {
cc.isAddedHiddenEvent = false;
window.addEventListener("focus", function () {
var audioEngine = cc.AudioEngine.getInstance();
audioEngine.resumeAllEffects();
audioEngine.resumeMusic();
}, false);
window.addEventListener("blur", function () {
var audioEngine = cc.AudioEngine.getInstance();
audioEngine.pauseAllEffects();
audioEngine.pauseMusic();
}, false);
} else {
cc.isAddedHiddenEvent = true;
document.addEventListener(visibilityChange, handleVisibilityChange, false);
Expand All @@ -275,7 +295,8 @@ cc._addUserSelectStatus = function(){
cc._addBottomTag = function () {
var bottom = document.createElement("div");
bottom.id = "bottom";
bottom.style.border = bottom.style.margin = bottom.style.padding = bottom.style.height = bottom.style.lineHeight = bottom.style.fontSize = "0px";
var bStyle = bottom.style;
bStyle.border = bStyle.margin = bStyle.padding = bStyle.height = bStyle.lineHeight = bStyle.fontSize = "0px";
document.body.appendChild(bottom);
window.location.href="#bottom";
};
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/platform/CCClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ ClassManager.getNewInstanceId=function(){

// The dummy Class constructor
function Class() {
this.__instanceId = ClassManager.getNewInstanceId();
// All construction is actually done in the init method
if (this.ctor)
this.ctor.apply(this, arguments);
this.__instanceId = ClassManager.getNewInstanceId();
}

Class.id = classId;
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/platform/CCCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ cc._logToWebPage = function (message) {
logList = document.createElement("ul");
logDiv.appendChild(logList);
logList.setAttribute("id", "logInfoList");
logList.style.height = "200px";
logList.style.height = cc.canvas.height + "px";
logList.style.color = "#fff";
logList.style.textAlign = "left";
logList.style.listStyle = "disc outside";
Expand Down
2 changes: 1 addition & 1 deletion samples