diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index c71e912..a6a22f0 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -504,6 +504,10 @@ // update the touch position touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); + if(navigator.isCocoonJS) { + touchData.global.x = touchEvent.clientX; + touchData.global.y = touchEvent.clientY; + } } var length = this.interactiveItems.length; @@ -539,6 +543,10 @@ this.touchs[touchEvent.identifier] = touchData; touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); + if(navigator.isCocoonJS) { + touchData.global.x = touchEvent.clientX; + touchData.global.y = touchEvent.clientY; + } var length = this.interactiveItems.length; @@ -584,6 +592,10 @@ var up = false; touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); + if(navigator.isCocoonJS) { + touchData.global.x = touchEvent.clientX; + touchData.global.y = touchEvent.clientY; + } var length = this.interactiveItems.length; for (var j = 0; j < length; j++) diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index c71e912..a6a22f0 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -504,6 +504,10 @@ // update the touch position touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); + if(navigator.isCocoonJS) { + touchData.global.x = touchEvent.clientX; + touchData.global.y = touchEvent.clientY; + } } var length = this.interactiveItems.length; @@ -539,6 +543,10 @@ this.touchs[touchEvent.identifier] = touchData; touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); + if(navigator.isCocoonJS) { + touchData.global.x = touchEvent.clientX; + touchData.global.y = touchEvent.clientY; + } var length = this.interactiveItems.length; @@ -584,6 +592,10 @@ var up = false; touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); + if(navigator.isCocoonJS) { + touchData.global.x = touchEvent.clientX; + touchData.global.y = touchEvent.clientY; + } var length = this.interactiveItems.length; for (var j = 0; j < length; j++) diff --git a/src/pixi/loaders/BitmapFontLoader.js b/src/pixi/loaders/BitmapFontLoader.js index 8421f90..d00a494 100644 --- a/src/pixi/loaders/BitmapFontLoader.js +++ b/src/pixi/loaders/BitmapFontLoader.js @@ -91,36 +91,48 @@ { if (this.ajaxRequest.status === 200 || window.location.protocol.indexOf('http') === -1) { - var textureUrl = this.baseUrl + this.ajaxRequest.responseXML.getElementsByTagName('page')[0].attributes.getNamedItem('file').nodeValue; + var responseXML = this.ajaxRequest.responseXML; + if(!responseXML || /MSIE 9/i.test(navigator.userAgent) || navigator.isCocoonJS) { + if(typeof(window.DOMParser) === 'function') { + var domparser = new DOMParser(); + responseXML = domparser.parseFromString(this.ajaxRequest.responseText, 'text/xml'); + } else { + var div = document.createElement('div'); + div.innerHTML = this.ajaxRequest.responseText; + responseXML = div; + } + } + + var textureUrl = this.baseUrl + responseXML.getElementsByTagName('page')[0].getAttribute('file'); var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); this.texture = image.texture.baseTexture; var data = {}; - var info = this.ajaxRequest.responseXML.getElementsByTagName('info')[0]; - var common = this.ajaxRequest.responseXML.getElementsByTagName('common')[0]; - data.font = info.attributes.getNamedItem('face').nodeValue; - data.size = parseInt(info.attributes.getNamedItem('size').nodeValue, 10); - data.lineHeight = parseInt(common.attributes.getNamedItem('lineHeight').nodeValue, 10); + var info = responseXML.getElementsByTagName('info')[0]; + var common = responseXML.getElementsByTagName('common')[0]; + data.font = info.getAttribute('face'); + data.size = parseInt(info.getAttribute('size'), 10); + data.lineHeight = parseInt(common.getAttribute('lineHeight'), 10); data.chars = {}; //parse letters - var letters = this.ajaxRequest.responseXML.getElementsByTagName('char'); + var letters = responseXML.getElementsByTagName('char'); for (var i = 0; i < letters.length; i++) { - var charCode = parseInt(letters[i].attributes.getNamedItem('id').nodeValue, 10); + var charCode = parseInt(letters[i].getAttribute('id'), 10); var textureRect = new PIXI.Rectangle( - parseInt(letters[i].attributes.getNamedItem('x').nodeValue, 10), - parseInt(letters[i].attributes.getNamedItem('y').nodeValue, 10), - parseInt(letters[i].attributes.getNamedItem('width').nodeValue, 10), - parseInt(letters[i].attributes.getNamedItem('height').nodeValue, 10) + parseInt(letters[i].getAttribute('x'), 10), + parseInt(letters[i].getAttribute('y'), 10), + parseInt(letters[i].getAttribute('width'), 10), + parseInt(letters[i].getAttribute('height'), 10) ); data.chars[charCode] = { - xOffset: parseInt(letters[i].attributes.getNamedItem('xoffset').nodeValue, 10), - yOffset: parseInt(letters[i].attributes.getNamedItem('yoffset').nodeValue, 10), - xAdvance: parseInt(letters[i].attributes.getNamedItem('xadvance').nodeValue, 10), + xOffset: parseInt(letters[i].getAttribute('xoffset'), 10), + yOffset: parseInt(letters[i].getAttribute('yoffset'), 10), + xAdvance: parseInt(letters[i].getAttribute('xadvance'), 10), kerning: {}, texture: PIXI.TextureCache[charCode] = new PIXI.Texture(this.texture, textureRect) @@ -128,12 +140,12 @@ } //parse kernings - var kernings = this.ajaxRequest.responseXML.getElementsByTagName('kerning'); + var kernings = responseXML.getElementsByTagName('kerning'); for (i = 0; i < kernings.length; i++) { - var first = parseInt(kernings[i].attributes.getNamedItem('first').nodeValue, 10); - var second = parseInt(kernings[i].attributes.getNamedItem('second').nodeValue, 10); - var amount = parseInt(kernings[i].attributes.getNamedItem('amount').nodeValue, 10); + var first = parseInt(kernings[i].getAttribute('first'), 10); + var second = parseInt(kernings[i].getAttribute('second'), 10); + var amount = parseInt(kernings[i].getAttribute('amount'), 10); data.chars[second].kerning[first] = amount; diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index c71e912..a6a22f0 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -504,6 +504,10 @@ // update the touch position touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); + if(navigator.isCocoonJS) { + touchData.global.x = touchEvent.clientX; + touchData.global.y = touchEvent.clientY; + } } var length = this.interactiveItems.length; @@ -539,6 +543,10 @@ this.touchs[touchEvent.identifier] = touchData; touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); + if(navigator.isCocoonJS) { + touchData.global.x = touchEvent.clientX; + touchData.global.y = touchEvent.clientY; + } var length = this.interactiveItems.length; @@ -584,6 +592,10 @@ var up = false; touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); + if(navigator.isCocoonJS) { + touchData.global.x = touchEvent.clientX; + touchData.global.y = touchEvent.clientY; + } var length = this.interactiveItems.length; for (var j = 0; j < length; j++) diff --git a/src/pixi/loaders/BitmapFontLoader.js b/src/pixi/loaders/BitmapFontLoader.js index 8421f90..d00a494 100644 --- a/src/pixi/loaders/BitmapFontLoader.js +++ b/src/pixi/loaders/BitmapFontLoader.js @@ -91,36 +91,48 @@ { if (this.ajaxRequest.status === 200 || window.location.protocol.indexOf('http') === -1) { - var textureUrl = this.baseUrl + this.ajaxRequest.responseXML.getElementsByTagName('page')[0].attributes.getNamedItem('file').nodeValue; + var responseXML = this.ajaxRequest.responseXML; + if(!responseXML || /MSIE 9/i.test(navigator.userAgent) || navigator.isCocoonJS) { + if(typeof(window.DOMParser) === 'function') { + var domparser = new DOMParser(); + responseXML = domparser.parseFromString(this.ajaxRequest.responseText, 'text/xml'); + } else { + var div = document.createElement('div'); + div.innerHTML = this.ajaxRequest.responseText; + responseXML = div; + } + } + + var textureUrl = this.baseUrl + responseXML.getElementsByTagName('page')[0].getAttribute('file'); var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); this.texture = image.texture.baseTexture; var data = {}; - var info = this.ajaxRequest.responseXML.getElementsByTagName('info')[0]; - var common = this.ajaxRequest.responseXML.getElementsByTagName('common')[0]; - data.font = info.attributes.getNamedItem('face').nodeValue; - data.size = parseInt(info.attributes.getNamedItem('size').nodeValue, 10); - data.lineHeight = parseInt(common.attributes.getNamedItem('lineHeight').nodeValue, 10); + var info = responseXML.getElementsByTagName('info')[0]; + var common = responseXML.getElementsByTagName('common')[0]; + data.font = info.getAttribute('face'); + data.size = parseInt(info.getAttribute('size'), 10); + data.lineHeight = parseInt(common.getAttribute('lineHeight'), 10); data.chars = {}; //parse letters - var letters = this.ajaxRequest.responseXML.getElementsByTagName('char'); + var letters = responseXML.getElementsByTagName('char'); for (var i = 0; i < letters.length; i++) { - var charCode = parseInt(letters[i].attributes.getNamedItem('id').nodeValue, 10); + var charCode = parseInt(letters[i].getAttribute('id'), 10); var textureRect = new PIXI.Rectangle( - parseInt(letters[i].attributes.getNamedItem('x').nodeValue, 10), - parseInt(letters[i].attributes.getNamedItem('y').nodeValue, 10), - parseInt(letters[i].attributes.getNamedItem('width').nodeValue, 10), - parseInt(letters[i].attributes.getNamedItem('height').nodeValue, 10) + parseInt(letters[i].getAttribute('x'), 10), + parseInt(letters[i].getAttribute('y'), 10), + parseInt(letters[i].getAttribute('width'), 10), + parseInt(letters[i].getAttribute('height'), 10) ); data.chars[charCode] = { - xOffset: parseInt(letters[i].attributes.getNamedItem('xoffset').nodeValue, 10), - yOffset: parseInt(letters[i].attributes.getNamedItem('yoffset').nodeValue, 10), - xAdvance: parseInt(letters[i].attributes.getNamedItem('xadvance').nodeValue, 10), + xOffset: parseInt(letters[i].getAttribute('xoffset'), 10), + yOffset: parseInt(letters[i].getAttribute('yoffset'), 10), + xAdvance: parseInt(letters[i].getAttribute('xadvance'), 10), kerning: {}, texture: PIXI.TextureCache[charCode] = new PIXI.Texture(this.texture, textureRect) @@ -128,12 +140,12 @@ } //parse kernings - var kernings = this.ajaxRequest.responseXML.getElementsByTagName('kerning'); + var kernings = responseXML.getElementsByTagName('kerning'); for (i = 0; i < kernings.length; i++) { - var first = parseInt(kernings[i].attributes.getNamedItem('first').nodeValue, 10); - var second = parseInt(kernings[i].attributes.getNamedItem('second').nodeValue, 10); - var amount = parseInt(kernings[i].attributes.getNamedItem('amount').nodeValue, 10); + var first = parseInt(kernings[i].getAttribute('first'), 10); + var second = parseInt(kernings[i].getAttribute('second'), 10); + var amount = parseInt(kernings[i].getAttribute('amount'), 10); data.chars[second].kerning[first] = amount; diff --git a/src/pixi/text/Text.js b/src/pixi/text/Text.js index 08a98c5..48e81d4 100644 --- a/src/pixi/text/Text.js +++ b/src/pixi/text/Text.js @@ -109,6 +109,8 @@ var lineHeight = this.determineFontHeight('font: ' + this.style.font + ';') + this.style.strokeThickness; this.canvas.height = lineHeight * lines.length; + if(navigator.isCocoonJS) this.context.clearRect(0,0,this.canvas.width,this.canvas.height); + //set canvas text styles this.context.fillStyle = this.style.fill; this.context.font = this.style.font;