Permalink
Browse files

fixed #1463 CCBReader compatibility with IE9 and check event handler…

… of cc.Node for EventDispatcher
  • Loading branch information...
dingpinglv committed Nov 20, 2012
1 parent b877485 commit 57b33f0b045a08df95ebb7748ab57021a8ac76ce
View
@@ -152,7 +152,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
_scenesStack:null,
_projectionDelegate:null,
_runningScene:null,
- _szFPS:'',
+
_frames:0,
_totalFrames:0,
_secondsPerFrame:0,
@@ -213,7 +213,6 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
this._frameRate = 0;
this._displayStats = false;//can remove
this._totalFrames = this._frames = 0;
- this._szFPS = "";
this._lastUpdate = new cc.timeval();
//Paused?
@@ -925,9 +924,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
this._frames = 0;
this._accumDt = 0;
- this._szFPS = ('' + this._frameRate.toFixed(1));
- this._FPSLabel.setString(this._szFPS);
-
+ this._FPSLabel.setString(this._frameRate.toFixed(1));
this._drawsLabel.setString((0 | cc.g_NumberOfDraws).toString());
}
this._FPSLabel.visit();
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -56,6 +56,7 @@
setPosition:function (p) {
var angle = this._body.GetAngle();
this._body.setTransform(Box2D.b2Vec2(p.x / this._PTMRatio, p.y / this._PTMRatio), angle);
+ this.setNodeDirty();
},
getRotation:function () {
return (this._ignoreBodyRotation ? cc.RADIANS_TO_DEGREES(this._rotationRadians) : cc.RADIANS_TO_DEGREES(this._body.GetAngle()));
@@ -68,6 +69,7 @@
var p = this._body.GetPosition();
this._body.SetTransform(p, cc.DEGREES_TO_RADIANS(r));
}
+ this.setNodeDirty();
},
_syncPosition:function () {
var pos = this._body.GetPosition();
@@ -108,7 +110,10 @@
//this._syncPosition();
},
_syncPosition:function () {
- this._position = {x:this._body.p.x, y:this._body.p.y};
+ if(this._position.x != this._body.p.x && this._position.y != this._body.p.y){
+ this._position = {x:this._body.p.x, y:this._body.p.y};
+ this.setNodeDirty();
+ }
},
getRotation:function () {
return this._ignoreBodyRotation ? cc.RADIANS_TO_DEGREES(this._rotationRadians) : -cc.RADIANS_TO_DEGREES(this._body.a)
@@ -123,7 +128,10 @@
}
},
_syncRotation:function () {
- this._rotationRadians = -this._body.a;
+ if(this._rotationRadians != -this._body.a){
+ this._rotationRadians = -this._body.a;
+ this.setNodeDirty();
+ }
},
visit:function (ctx) {
if (this._body) {
@@ -66,14 +66,60 @@ cc.SAX_STRING = 5;
*/
cc.SAX_ARRAY = 6;
+//Compatibility with IE9
+var Uint8Array = Uint8Array || Array;
+
+if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
+ var IEBinaryToArray_ByteStr_Script =
+ "<!-- IEBinaryToArray_ByteStr -->\r\n" +
+ //"<script type='text/vbscript'>\r\n" +
+ "Function IEBinaryToArray_ByteStr(Binary)\r\n" +
+ " IEBinaryToArray_ByteStr = CStr(Binary)\r\n" +
+ "End Function\r\n" +
+ "Function IEBinaryToArray_ByteStr_Last(Binary)\r\n" +
+ " Dim lastIndex\r\n" +
+ " lastIndex = LenB(Binary)\r\n" +
+ " if lastIndex mod 2 Then\r\n" +
+ " IEBinaryToArray_ByteStr_Last = Chr( AscB( MidB( Binary, lastIndex, 1 ) ) )\r\n" +
+ " Else\r\n" +
+ " IEBinaryToArray_ByteStr_Last = " + '""' + "\r\n" +
+ " End If\r\n" +
+ "End Function\r\n";// +
+ //"</script>\r\n";
+
+ // inject VBScript
+ //document.write(IEBinaryToArray_ByteStr_Script);
+ var myVBScript = document.createElement('script');
+ myVBScript.type = "text/vbscript";
+ myVBScript.textContent = IEBinaryToArray_ByteStr_Script;
+ document.body.appendChild(myVBScript);
+
+ // helper to convert from responseBody to a "responseText" like thing
+ cc._convertResponseBodyToText = function (binary) {
+ var byteMapping = {};
+ for (var i = 0; i < 256; i++) {
+ for (var j = 0; j < 256; j++) {
+ byteMapping[ String.fromCharCode(i + j * 256) ] =
+ String.fromCharCode(i) + String.fromCharCode(j);
+ }
+ }
+ var rawBytes = IEBinaryToArray_ByteStr(binary);
+ var lastChr = IEBinaryToArray_ByteStr_Last(binary);
+ return rawBytes.replace(/[\s\S]/g,
+ function (match) {
+ return byteMapping[match];
+ }) + lastChr;
+ };
+}
+
/**
* @namespace
*/
cc.FileUtils = cc.Class.extend({
_fileDataCache:null,
- ctor:function(){
- this._fileDataCache = {};
+ ctor:function () {
+ this._fileDataCache = {};
},
/**
* Get resource file data
@@ -84,51 +130,88 @@ cc.FileUtils = cc.Class.extend({
* @warning If you get the file data succeed,you must delete it after used.
*/
getFileData:function (fileName, mode, size) {
- if(this._fileDataCache.hasOwnProperty(fileName))
+ if (this._fileDataCache.hasOwnProperty(fileName))
return this._fileDataCache[fileName];
return this._loadBinaryFileData(fileName);
},
- preloadBinaryFileData:function(fileUrl){
- fileUrl = this.fullPathFromRelativePath(fileUrl);
+ _getXMLHttpRequest:function () {
+ if (window.XMLHttpRequest) {
+ return new window.XMLHttpRequest();
+ } else {
+ return new ActiveXObject("MSXML2.XMLHTTP");
+ }
+ },
+ preloadBinaryFileData:function (fileUrl) {
+ fileUrl = this.fullPathFromRelativePath(fileUrl);
var selfPointer = this;
- var xhr = new XMLHttpRequest();
+
+ var xhr = this._getXMLHttpRequest();
xhr.open("GET", fileUrl, true);
- if(xhr.overrideMimeType)
- xhr.overrideMimeType("text\/plain; charset=x-user-defined");
- xhr.onload = function(e) {
- var arrayStr = xhr.responseText;
- if(arrayStr){
- cc.Loader.getInstance().onResLoaded();
- selfPointer._fileDataCache[fileUrl] = selfPointer._stringConvertToArray(arrayStr);
- }
- };
+ if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
+ // IE-specific logic here
+ xhr.setRequestHeader("Accept-Charset", "x-user-defined");
+ xhr.onreadystatechange = function (event) {
+ if (xhr.readyState == 4) {
+ if (xhr.status == 200) {
+ var fileContents = cc._convertResponseBodyToText(xhr.responseBody);
+ if (fileContents)
+ selfPointer._fileDataCache[fileUrl] = selfPointer._stringConvertToArray(fileContents);
+ }
+ cc.Loader.getInstance().onResLoaded();
+ }
+ };
+ } else {
+ if (xhr.overrideMimeType)
+ xhr.overrideMimeType("text\/plain; charset=x-user-defined");
+ xhr.onload = function (e) {
+ var arrayStr = xhr.responseText;
+ if (arrayStr) {
+ cc.Loader.getInstance().onResLoaded();
+ selfPointer._fileDataCache[fileUrl] = selfPointer._stringConvertToArray(arrayStr);
+ }
+ };
+ }
xhr.send(null);
},
- _loadBinaryFileData:function(fileUrl){
- var req = new XMLHttpRequest();
+ _loadBinaryFileData:function (fileUrl) {
+ var req = this._getXMLHttpRequest();
req.open('GET', fileUrl, false);
- if(req.overrideMimeType)
- req.overrideMimeType('text\/plain; charset=x-user-defined');
- req.send(null);
- if (req.status != 200)
- return '';
-
- var arrayInfo = this._stringConvertToArray(req.responseText);
- this._fileDataCache[fileUrl] = arrayInfo;
+ var arrayInfo = null;
+ if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
+ req.setRequestHeader("Accept-Charset", "x-user-defined");
+ req.send(null);
+ if (req.status != 200)
+ return null;
+
+ var fileContents = cc._convertResponseBodyToText(req.responseBody);
+ if(fileContents){
+ arrayInfo = this._stringConvertToArray(req.responseText);
+ this._fileDataCache[fileUrl] = arrayInfo;
+ }
+ } else {
+ if (req.overrideMimeType)
+ req.overrideMimeType('text\/plain; charset=x-user-defined');
+ req.send(null);
+ if (req.status != 200)
+ return null;
+
+ arrayInfo = this._stringConvertToArray(req.responseText);
+ this._fileDataCache[fileUrl] = arrayInfo;
+ }
return arrayInfo;
},
- _stringConvertToArray:function(strData){
- if(!strData)
+ _stringConvertToArray:function (strData) {
+ if (!strData)
return null;
var arrData = new Uint8Array(strData.length);
- for(var i = 0; i< strData.length; i++){
- arrData[i] = strData.charCodeAt(i) ; //& 0xff;
+ for (var i = 0; i < strData.length; i++) {
+ arrData[i] = strData.charCodeAt(i) & 0xff;
}
return arrData;
},
@@ -261,9 +344,9 @@ cc.FileUtils = cc.Class.extend({
});
cc.s_SharedFileUtils = null;
-cc.FileUtils.getInstance = function(){
- if(cc.s_SharedFileUtils == null){
- cc.s_SharedFileUtils = new cc.FileUtils();
+cc.FileUtils.getInstance = function () {
+ if (cc.s_SharedFileUtils == null) {
+ cc.s_SharedFileUtils = new cc.FileUtils();
}
return cc.s_SharedFileUtils;
};
@@ -224,6 +224,5 @@ cc.ParallaxNode = cc.Node.extend(/** @lends cc.ParallaxNode# */{
* var voidNode = cc.ParallaxNode.create();
*/
cc.ParallaxNode.create = function () {
- var ret = new cc.ParallaxNode();
- return ret;
+ return new cc.ParallaxNode();
};
@@ -425,30 +425,38 @@ cc.MouseDispatcher = cc.Class.extend({
},
mouseHandle:function (mouseObj, event, index) {
- for(var i = 0 ; i < this._mouseDelegateHandlers.length; i++){
+ for (var i = 0; i < this._mouseDelegateHandlers.length; i++) {
var handler = this._mouseDelegateHandlers[i];
- switch(index){
+ switch (index) {
case cc.MOUSE_DOWN:
- handler.getDelegate().onMouseDown(mouseObj);
+ if (handler.getDelegate().onMouseDown)
+ handler.getDelegate().onMouseDown(mouseObj);
break;
case cc.MOUSE_UP:
- handler.getDelegate().onMouseUp(mouseObj);
+ if (handler.getDelegate().onMouseUp)
+ handler.getDelegate().onMouseUp(mouseObj);
break;
case cc.MOUSE_MOVED:
- if(this._mousePressed)
- handler.getDelegate().onMouseDragged(mouseObj);
- else
- handler.getDelegate().onMouseMoved(mouseObj);
+ if (this._mousePressed) {
+ if (handler.getDelegate().onMouseDragged)
+ handler.getDelegate().onMouseDragged(mouseObj);
+ } else {
+ if (handler.getDelegate().onMouseMoved)
+ handler.getDelegate().onMouseMoved(mouseObj);
+ }
break;
case cc.MOUSE_ENTERED:
- handler.getDelegate().onMouseEntered(mouseObj);
+ if (handler.getDelegate().onMouseEntered)
+ handler.getDelegate().onMouseEntered(mouseObj);
break;
case cc.MOUSE_EXITED:
- handler.getDelegate().onMouseExited(mouseObj);
+ if (handler.getDelegate().onMouseExited)
+ handler.getDelegate().onMouseExited(mouseObj);
break;
case cc.SCROLL_WHEEL:
- handler.getDelegate().onScrollWheel(mouseObj);
+ if (handler.getDelegate().onScrollWheel)
+ handler.getDelegate().onScrollWheel(mouseObj);
break;
}
}
Oops, something went wrong.

0 comments on commit 57b33f0

Please sign in to comment.