Permalink
Browse files

Merge branch 'master' of https://github.com/cocos2d/cocos2d-html5 int…

…o iss1518_MouseDispatcher
  • Loading branch information...
2 parents 4f8e230 + 78ff1a1 commit d1b2165fa900d4d682eaab71242d4d5b09f1b541 @dingpinglv dingpinglv committed Dec 17, 2012
@@ -36,6 +36,7 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
_soundEnable:false,
_effectList:{},
_muiscList:{},
+ _soundList:{},
_isMusicPlaying:false,
_playingMusic:null,
_effectsVolume:1,
@@ -83,11 +84,11 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
* This method is called when cc.Loader preload resources.
* @param {String} path The path of the music file with filename extension.
*/
- preloadMusic:function (path) {
+ preloadSound:function (path) {
if (this._soundEnable) {
var extName = this._getExtFromFullPath(path);
var keyname = this._getPathWithoutExt(path);
- if (this._checkAudioFormatSupported(extName) && !this._muiscList.hasOwnProperty(keyname)) {
+ if (this._checkAudioFormatSupported(extName) && !this._soundList.hasOwnProperty(keyname)) {
var soundCache = new Audio(path);
soundCache.preload = 'auto';
@@ -96,21 +97,13 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
}, false);
soundCache.addEventListener("error", function (e) {
+ this.removeEventListener('error', arguments.callee, false);
cc.Loader.getInstance().onResLoadingErr();
}, false);
- soundCache.addEventListener("playing", function (e) {
- cc.AudioEngine._instance._isMusicPlaying = true;
- }, false);
-
- soundCache.addEventListener("pause", function (e) {
- cc.AudioEngine._instance._isMusicPlaying = false;
- }, false);
-
+ this._soundList[keyname] = true;
// load it
soundCache.load();
-
- this._muiscList[keyname] = soundCache
}
}
cc.Loader.getInstance().onResLoaded();
@@ -126,14 +119,31 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
*/
playMusic:function (path, loop) {
var keyname = this._getPathWithoutExt(path);
+ var actExt = this._supportedFormat[0];
+ var au;
if (this._muiscList.hasOwnProperty(this._playingMusic)) {
this._muiscList[this._playingMusic].pause();
}
this._playingMusic = keyname;
if (this._muiscList.hasOwnProperty(this._playingMusic)) {
- this._muiscList[this._playingMusic].loop = loop || false;
- this._muiscList[this._playingMusic].play();
+ au = this._muiscList[this._playingMusic];
}
+ else {
+ au = new Audio(keyname + "." + actExt);
+ au.preload = 'auto';
+ this._muiscList[this._playingMusic] = au;
+
+ au.addEventListener("playing", function (e) {
+ cc.AudioEngine._instance._isMusicPlaying = true;
+ }, false);
+
+ au.addEventListener("pause", function (e) {
+ cc.AudioEngine._instance._isMusicPlaying = false;
+ }, false);
+ }
+
+ au.loop = loop || false;
+ au.play();
},
/**
@@ -145,9 +155,10 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
*/
stopMusic:function (releaseData) {
if (this._muiscList.hasOwnProperty(this._playingMusic)) {
- this._muiscList[this._playingMusic].pause();
- this._muiscList[this._playingMusic].currentTime = 0;
- if (releaseData && this._muiscList.hasOwnProperty(this._playingMusic)) {
+ var au = this._muiscList[this._playingMusic];
+ au.pause();
+ au.currentTime = au.duration;
+ if (releaseData) {
delete this._muiscList[this._playingMusic];
}
}
@@ -189,6 +200,7 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
this._muiscList[this._playingMusic].play();
}
},
+
willPlayMusic:function () {
return false;
},
@@ -246,25 +258,8 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
},
/**
- * Preload sound effect resource.
- * This method is called when cc.Loader preload resources.
- * @param {String} path The path of the sound effect file with filename extension.
- */
- preloadEffect:function (path) {
- if (this._soundEnable) {
- var extName = this._getExtFromFullPath(path);
- var keyname = this._getPathWithoutExt(path);
- if (this._checkAudioFormatSupported(extName) && !this._effectList.hasOwnProperty(keyname)) {
- this._effectList[keyname] = [];
- this._effectList[keyname].push(new Audio(path));
- }
- }
- cc.Loader.getInstance().onResLoaded();
- },
-
- /**
* Play sound effect.
- * @param {String} path The path of the sound effect without filename extension.
+ * @param {String} path The path of the sound effect with filename extension.
* @param {Boolean} loop Whether to loop the effect playing, default value is false
* @example
* //example
@@ -274,7 +269,7 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
var keyname = this._getPathWithoutExt(path);
var actExt = this._supportedFormat[0];
var reclaim = this._getEffectList(keyname), au;
- if(reclaim.length > 0){
+ if (reclaim.length > 0) {
for (var i = 0; i < reclaim.length; i++) {
//if one of the effect ended, play it
if (reclaim[i].ended) {
@@ -284,12 +279,13 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
}
}
}
- if (!au){
+
+ if (!au) {
if (reclaim.length >= this._maxAudioInstance) {
cc.log("Error: " + path + " greater than " + this._maxAudioInstance);
return keyname;
}
- au = new Audio(keyname+"."+actExt);
+ au = new Audio(keyname + "." + actExt);
reclaim.push(au);
}
@@ -478,6 +474,7 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
unloadEffect:function (path) {
var keyname = this._getPathWithoutExt(path);
if (this._effectList.hasOwnProperty(keyname)) {
+ this.stopEffect(path);
delete this._effectList[keyname];
}
},
@@ -498,7 +495,8 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
return this._effectList[elt];
}
else {
- return [];
+ this._effectList[elt] = [];
+ return this._effectList[elt];
}
},
View
@@ -163,11 +163,8 @@ cc.Loader = cc.Class.extend(/** @lends cc.Loader# */{
case "image":
sharedTextureCache.addImage(res[i].src);
break;
- case "bgm":
- sharedEngine.preloadMusic(res[i].src);
- break;
- case "effect":
- sharedEngine.preloadEffect(res[i].src);
+ case "sound":
+ sharedEngine.preloadSound(res[i].src);
break;
case "plist":
case "tmx":
@@ -275,10 +275,10 @@ cc.DrawNode = cc.Node.extend({
},
/** draw a polygon with a fill color and line color */
- drawPolyWithVerts:function (verts, count, fillColor, width, borderColor) {
+ drawPoly:function (verts, fillColor, width, borderColor) {
var element = new cc._DrawNodeElement(cc.DRAWNODE_TYPE_POLY);
- element.verts = cc.DrawNode.convertVerts(verts);
- element.count = count;
+ element.verts = verts;
+ element.count = verts.length;
element.fillColor = fillColor;
element.borderWidth = width;
element.borderColor = borderColor;
@@ -395,10 +395,3 @@ cc._DrawNodeElement = function (type) {
cc.DRAWNODE_TYPE_DOT = 0;
cc.DRAWNODE_TYPE_SEGMENT = 1;
cc.DRAWNODE_TYPE_POLY = 2;
-cc.DrawNode.convertVerts = function (verts) {
- var ret = [];
- for (var i = 0; i < verts.length / 2; i++) {
- ret[i] = {x:verts[i * 2], y:verts[i * 2 + 1]};
- }
- return ret;
-};
@@ -34,6 +34,15 @@
as the private API may change with little or no warning.
*/
+// Helper. Converts an array of numbers into an array of vectors(x,y)
+cc.__convertVerts = function (verts) {
+ var ret = [];
+ for (var i = 0; i < verts.length / 2; i++) {
+ ret[i] = {x:verts[i * 2], y:verts[i * 2 + 1]};
+ }
+ return ret;
+};
+
cc.ColorForBody = function (body) {
if (body.isRogue() || body.isSleeping()) {
return cc.c4f(0.5, 0.5, 0.5, 0.5);
@@ -57,7 +66,7 @@ cc.DrawShape = function (shape, renderer) {
break;
case cp.PolyShape.prototype.collisionCode:
var line = cc.c4f(color.r, color.g, color.b, cc.lerp(color.a, 1.0, 0.5));
- this.drawPolyWithVerts(shape.tVerts, shape.getNumVerts(), color, 1.0, line);
+ this.drawPoly(cc.__convertVerts(shape.tVerts), color, 1.0, line);
break;
default:
cc.Assert(false, "Bad assertion in DrawShape()");
@@ -153,4 +162,5 @@ cc.PhysicsDebugNode.debugNodeForCPSpace = function (space) {
return null;
};
-cc.PhysicsDebugNode.create = cc.PhysicsDebugNode.debugNodeForCPSpace;
+cc.PhysicsDebugNode.create = cc.PhysicsDebugNode.debugNodeForCPSpace;
+
View
@@ -5,7 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="icon"
type="image/GIF"
- href="tests/res/Images/favicon.ico"/>
+ href="samples/tests/res/Images/favicon.ico"/>
<link href='http://fonts.googleapis.com/css?family=Nunito:700,300' rel='stylesheet' type='text/css'>
<style type="text/css">
body {
@@ -46,14 +46,17 @@
</style>
</head>
<body style="background: #f2f6f8;">
-<h1><a href="index.html"><img src="tests/res/Images/cocos2dbanner.png"/></a>
+<h1><a href="index.html"><img src="samples/tests/res/Images/cocos2dbanner.png"/></a>
</h1>
<hr/>
<ol>
<li><a href="HelloHTML5World/index.html">Hello World</a> <span
class="comment"> - Hello World for Cocos2d-HTML5</span></li>
- <li><a href="tests/index.html">Test cases</a> <span class="comment"> - Engine Testcases</span></li>
+ <li><a href="samples/tests/index.html">Test cases</a> <span class="comment"> - Engine Testcases</span></li>
<li><a href="Demo/index.html">Demos</a> <span class="comment"> - Platform Demos</span></li>
+ <li><a href="samples/games/MoonWarriors/index.html">MoonWarriors</a> <span class="comment"> - game</span></li>
+ <li><a href="samples/games/WatermelonWithMe/index.html">Watermelon with Me</a> <span class="comment"> - game</span></li>
+ <li><a href="samples/games/CocosDragonJS/Published files HTML5/index.html">CocosDragon</a> <span class="comment"> - game</span></li>
</ol>
<hr/>
<h2>Note</h2>
@@ -78,4 +81,4 @@
<p>Cocos2d-html5 should now work without any errors</p>
</div>
</body>
-</html>
+</html>

0 comments on commit d1b2165

Please sign in to comment.