Merge pull request #480 from ekelokorpi/dev

CocoonJS compatibility
This commit is contained in:
Mat Groves 2014-01-09 03:35:12 -08:00
commit 507a28e22c
2 changed files with 43 additions and 19 deletions

View file

@ -504,6 +504,10 @@ PIXI.InteractionManager.prototype.onTouchMove = function(event)
// update the touch position // update the touch position
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); 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; var length = this.interactiveItems.length;
@ -539,6 +543,10 @@ PIXI.InteractionManager.prototype.onTouchStart = function(event)
this.touchs[touchEvent.identifier] = touchData; this.touchs[touchEvent.identifier] = touchData;
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); 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; var length = this.interactiveItems.length;
@ -584,6 +592,10 @@ PIXI.InteractionManager.prototype.onTouchEnd = function(event)
var up = false; var up = false;
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); 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; var length = this.interactiveItems.length;
for (var j = 0; j < length; j++) for (var j = 0; j < length; j++)

View file

@ -91,36 +91,48 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
{ {
if (this.ajaxRequest.status === 200 || window.location.protocol.indexOf('http') === -1) 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); var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
this.texture = image.texture.baseTexture; this.texture = image.texture.baseTexture;
var data = {}; var data = {};
var info = this.ajaxRequest.responseXML.getElementsByTagName('info')[0]; var info = responseXML.getElementsByTagName('info')[0];
var common = this.ajaxRequest.responseXML.getElementsByTagName('common')[0]; var common = responseXML.getElementsByTagName('common')[0];
data.font = info.attributes.getNamedItem('face').nodeValue; data.font = info.getAttribute('face');
data.size = parseInt(info.attributes.getNamedItem('size').nodeValue, 10); data.size = parseInt(info.getAttribute('size'), 10);
data.lineHeight = parseInt(common.attributes.getNamedItem('lineHeight').nodeValue, 10); data.lineHeight = parseInt(common.getAttribute('lineHeight'), 10);
data.chars = {}; data.chars = {};
//parse letters //parse letters
var letters = this.ajaxRequest.responseXML.getElementsByTagName('char'); var letters = responseXML.getElementsByTagName('char');
for (var i = 0; i < letters.length; i++) 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( var textureRect = new PIXI.Rectangle(
parseInt(letters[i].attributes.getNamedItem('x').nodeValue, 10), parseInt(letters[i].getAttribute('x'), 10),
parseInt(letters[i].attributes.getNamedItem('y').nodeValue, 10), parseInt(letters[i].getAttribute('y'), 10),
parseInt(letters[i].attributes.getNamedItem('width').nodeValue, 10), parseInt(letters[i].getAttribute('width'), 10),
parseInt(letters[i].attributes.getNamedItem('height').nodeValue, 10) parseInt(letters[i].getAttribute('height'), 10)
); );
data.chars[charCode] = { data.chars[charCode] = {
xOffset: parseInt(letters[i].attributes.getNamedItem('xoffset').nodeValue, 10), xOffset: parseInt(letters[i].getAttribute('xoffset'), 10),
yOffset: parseInt(letters[i].attributes.getNamedItem('yoffset').nodeValue, 10), yOffset: parseInt(letters[i].getAttribute('yoffset'), 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem('xadvance').nodeValue, 10), xAdvance: parseInt(letters[i].getAttribute('xadvance'), 10),
kerning: {}, kerning: {},
texture: PIXI.TextureCache[charCode] = new PIXI.Texture(this.texture, textureRect) texture: PIXI.TextureCache[charCode] = new PIXI.Texture(this.texture, textureRect)
@ -128,12 +140,12 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
} }
//parse kernings //parse kernings
var kernings = this.ajaxRequest.responseXML.getElementsByTagName('kerning'); var kernings = responseXML.getElementsByTagName('kerning');
for (i = 0; i < kernings.length; i++) for (i = 0; i < kernings.length; i++)
{ {
var first = parseInt(kernings[i].attributes.getNamedItem('first').nodeValue, 10); var first = parseInt(kernings[i].getAttribute('first'), 10);
var second = parseInt(kernings[i].attributes.getNamedItem('second').nodeValue, 10); var second = parseInt(kernings[i].getAttribute('second'), 10);
var amount = parseInt(kernings[i].attributes.getNamedItem('amount').nodeValue, 10); var amount = parseInt(kernings[i].getAttribute('amount'), 10);
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;