Merge pull request #597 from knoxHuang/v1.0

Repair sprite-frame can not be displayed bug
This commit is contained in:
pandamicro
2016-04-22 00:00:17 +08:00
2 changed files with 33 additions and 71 deletions
-22
View File
@@ -119,28 +119,6 @@ cc.TextureCache.prototype.addImage = function(url, cb, target) {
}
};
// cc.SpriteFrame
cc.SpriteFrame.prototype._ctor = function (filename, rect, rotated, offset, originalSize) {
if (originalSize !== undefined) {
if(filename instanceof cc.Texture2D) {
this.initWithTexture(filename, rect, rotated, offset, originalSize);
}
else {
this.initWithTexture(filename, rect, rotated, offset, originalSize);
}
} else if (rect !== undefined) {
if(filename instanceof cc.Texture2D) {
this.initWithTexture(filename, rect);
}
else {
this.initWithTextureFilename(filename, rect);
}
} else if (filename instanceof cc.Texture2D) {
rect = cc.rect(0, 0, filename.getPixelWidth(), filename.getPixelHeight());
this.initWithTexture(filename, rect);
}
};
// setTimeout, setInterval, clearTimeout, clearInteval
var _windowTimeIntervalId = 0;
var _windowTimeFunHash = {};
+33 -49
View File
@@ -55,67 +55,51 @@ cc.js.mixin(cc.SpriteFrame.prototype, cc.EventTarget.prototype);
cc.SpriteFrame.prototype.textureLoaded = function () {
return this.getTexture() !== null;
};
// cc.SpriteFrame
cc.SpriteFrame.prototype._ctor = function (filename, rect, rotated, offset, originalSize) {
if (filename !== undefined) {
this.initWithTexture(filename, rect, rotated, offset, originalSize);
} else {
//todo log Error
}
};
cc.SpriteFrame.prototype._initWithTexture = cc.SpriteFrame.prototype.initWithTexture;
cc.SpriteFrame.prototype.initWithTexture = function (texture, rect, rotated, offset, originalSize, _uuid) {
function check(texture) {
cc.SpriteFrame.prototype.initWithTexture = function (textureOrTextureFile, rect, rotated, offset, originalSize) {
this.setTexture(textureOrTextureFile, rect, rotated, offset, originalSize);
};
cc.SpriteFrame.prototype.setTexture = function (textureOrTextureFile, rect, rotated, offset, originalSize) {
var texture = textureOrTextureFile;
if (cc.js.isString(texture)){
this._textureFilename = texture;
texture = cc.textureCache.addImage(texture);
}
if (texture instanceof cc.Texture2D) {
if (texture && texture.isLoaded()) {
var _x, _y;
if (rotated) {
_x = rect.x + rect.height;
_y = rect.y + rect.width;
if (rect) {
this._checkRect(texture);
}
else {
_x = rect.x + rect.width;
_y = rect.y + rect.height;
rect = cc.rect(0, 0, texture.width, texture.height);
}
if (_x > texture.getPixelWidth()) {
cc.error(cc._LogInfos.RectWidth, _uuid);
}
if (_y > texture.getPixelHeight()) {
cc.error(cc._LogInfos.RectHeight, _uuid);
}
}
}
offset = offset || cc.p(0, 0);
originalSize = originalSize || rect;
rotated = rotated || false;
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);
}
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);
this.emit('load');
}
}
this.emit('load');
check(this.getTexture());
return true;
};
cc.SpriteFrame.prototype._deserialize = function (data, handle) {
var rect = data.rect ? new cc.Rect(data.rect[0], data.rect[1], data.rect[2], data.rect[3]) : undefined;
var offset = data.offset ? new cc.Vec2(data.offset[0], data.offset[1]) : undefined;