Skip to content

Commit

Permalink
Merge pull request #69 from jwu/master
Browse files Browse the repository at this point in the history
use cc.Asset for sprite-atlas
  • Loading branch information
jwu committed Dec 17, 2015
2 parents 378199e + 14c60d5 commit d8e7295
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cocos2d/core/assets/CCSpriteAtlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
var SpriteAtlas = cc.Class({
name: 'cc.SpriteAtlas',
extends: cc.RawAsset,
extends: cc.Asset,
});

cc.SpriteAtlas = SpriteAtlas;
Expand Down
31 changes: 19 additions & 12 deletions cocos2d/core/components/CCSpriteRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var SpriteRenderer = cc.Class({
*/
_atlas: {
default: '',
url: cc.SpriteAtlas,
type: cc.SpriteAtlas,
editorOnly: true,
visible: true
},
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/sprites/CCSpriteFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit d8e7295

Please sign in to comment.