Merge pull request #69 from jwu/master

use cc.Asset for sprite-atlas
This commit is contained in:
Wu Jie
2015-12-17 16:43:19 +08:00
3 changed files with 21 additions and 14 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
*/
var SpriteAtlas = cc.Class({
name: 'cc.SpriteAtlas',
extends: cc.RawAsset,
extends: cc.Asset,
});
cc.SpriteAtlas = SpriteAtlas;
+19 -12
View File
@@ -55,7 +55,7 @@ var SpriteRenderer = cc.Class({
*/
_atlas: {
default: '',
url: cc.SpriteAtlas,
type: cc.SpriteAtlas,
editorOnly: true,
visible: true
},
@@ -77,18 +77,9 @@ var SpriteRenderer = cc.Class({
if (force) {
this._sgNode._scale9Image = null;
}
// Set atlas
if (value._atlasUuid !== undefined) {
var self = this;
cc.AssetLibrary.queryAssetInfo(value._atlasUuid, function(err, url) {
if (url) {
self._atlas = url;
}
else {
self._atlas = '';
}
});
}
this._applyAtlas(value);
}
this._applySprite(this._sgNode, lastSprite);
// color cleared after reset texture, should reapply color
@@ -452,6 +443,22 @@ var SpriteRenderer = cc.Class({
this.node.off('size-changed', this._resized, this);
},
_applyAtlas: CC_EDITOR && function ( sprite ) {
// Set atlas
if (sprite._atlasUuid !== undefined) {
var self = this;
cc.AssetLibrary.loadAsset(sprite._atlasUuid, function(err, asset) {
if (!asset) {
self._atlas = null;
return;
}
self._atlas = asset;
});
} else {
this._atlas = null;
}
},
_applyCapInset: function (node) {
if (this._type === SpriteType.SLICED) {
var node = node || this._sgNode;
+1 -1
View File
@@ -470,7 +470,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
return {
name: this._name,
texture: uuid,
atlas: exporting ? this._atlasUuid : undefined, // strip from json if exporting
atlas: exporting ? undefined : this._atlasUuid, // strip from json if exporting
rect: [rect.x, rect.y, rect.width, rect.height],
offset: [offset.x, offset.y],
originalSize: [size.width, size.height],