update polypill

This commit is contained in:
2youyouo2
2015-12-18 15:37:23 +08:00
parent 263e60b8d1
commit d3593b10a0
+49 -69
View File
@@ -422,72 +422,7 @@ cc.Texture2D.prototype.getPixelHeight = cc.Texture2D.prototype.getPixelsHigh;
cc.SpriteFrame.prototype.textureLoaded = function () {
return this.getTexture() !== null;
};
cc.SpriteFrame.prototype._initWithTexture = cc.SpriteFrame.prototype.initWithTexture;
cc.SpriteFrame.prototype.initWithTexture = function (texture, rect, rotated, offset, originalSize, _uuid) {
function check(texture) {
if (texture && texture.isLoaded()) {
var _x, _y;
if (rotated) {
_x = rect.x + rect.height;
_y = rect.y + rect.width;
}
else {
_x = rect.x + rect.width;
_y = rect.y + rect.height;
}
if (_x > texture.getPixelWidth()) {
cc.error(cc._LogInfos.RectWidth, _uuid);
}
if (_y > texture.getPixelHeight()) {
cc.error(cc._LogInfos.RectHeight, _uuid);
}
}
}
if(arguments.length === 2)
rect = cc.rectPointsToPixels(rect);
offset = offset || cc.p(0, 0);
originalSize = originalSize || rect;
rotated = rotated || false;
if (this.insetTop === undefined) {
this.insetTop = 0;
this.insetBottom = 0;
this.insetLeft = 0;
this.insetRight = 0;
}
var locTexture;
if (!texture && _uuid) {
// deserialize texture from uuid
var info = cc.AssetLibrary._getAssetInfoInRuntime(_uuid);
if (!info) {
cc.error('SpriteFrame: Failed to load sprite texture "%s"', _uuid);
return;
}
this._textureFilename = info.url;
locTexture = cc.textureCache.addImage(info.url);
this._initWithTexture(locTexture, rect, rotated, offset, originalSize);
// this.emit('load');
}
else {
if (cc.js.isString(texture)){
this._textureFilename = texture;
locTexture = cc.textureCache.addImage(this._textureFilename);
this._initWithTexture(locTexture, rect, rotated, offset, originalSize);
} else if (texture instanceof cc.Texture2D) {
this._textureFilename = '';
this._initWithTexture(texture, rect, rotated, offset, originalSize);
}
}
check(this.getTexture());
return true;
};
cc.SpriteFrame.prototype._deserialize = function (data) {
cc.SpriteFrame.prototype._deserialize = function (data, handle) {
var rect = data.rect;
rect = new cc.Rect(rect[0], rect[1], rect[2], rect[3]);
var rectInP = cc.rectPointsToPixels(rect);
@@ -505,10 +440,55 @@ cc.SpriteFrame.prototype._deserialize = function (data) {
this.insetRight = capInsets[2];
this.insetBottom = capInsets[3];
}
var uuid = data.texture;
this._loadingUuid = uuid;
this.initWithTexture(null, rectInP, rotated, offsetInP, sizeInP, uuid);
// load texture via _textureFilenameSetter
var textureUuid = data.texture;
if (textureUuid) {
handle.result.push(this, '_textureFilenameSetter', textureUuid);
}
this.initWithTexture(null, rectInP, rotated, offsetInP, sizeInP);
};
cc.SpriteFrame.prototype._checkRect = function (texture) {
var rect = this._rectInPixels;
var maxX = rect.x, maxY = rect.y;
if (this._rotated) {
maxX += rect.height;
maxY += rect.width;
}
else {
maxX += rect.width;
maxY += rect.height;
}
if (maxX > texture.getPixelWidth()) {
cc.error(cc._LogInfos.RectWidth, texture.url);
}
if (maxY > texture.getPixelHeight()) {
cc.error(cc._LogInfos.RectHeight, texture.url);
}
};
var getTextureJSB = cc.SpriteFrame.prototype.getTexture;
cc.SpriteFrame.prototype.getTexture = function () {
var tex = getTextureJSB.call(this);
this._texture = tex;
return tex;
};
cc.js.set(cc.SpriteFrame.prototype, '_textureFilenameSetter', function (url) {
this._textureFilename = url;
if (url) {
// texture will be init in getTexture()
var texture = this.getTexture();
if (this.textureLoaded()) {
this._checkRect(texture);
this.emit('load');
}
else {
// register event in setTexture()
this._texture = null;
this.setTexture(texture);
}
}
});
// cc.Label
cc.Label.prototype.setHorizontalAlign = cc.Label.prototype.setHorizontalAlignment;