mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-03 01:12:42 +08:00
support spine
This commit is contained in:
@@ -27,48 +27,6 @@
|
||||
* @module sp
|
||||
*/
|
||||
|
||||
// implements a simple texture loader like sp._atlasLoader
|
||||
var TextureLoader = !CC_JSB && cc.Class({
|
||||
ctor: function () {
|
||||
// {SkeletonData}
|
||||
this.asset = arguments[0];
|
||||
},
|
||||
getTexture: function (line) {
|
||||
//var name = cc.path.mainFileName(line);
|
||||
//var textures = this.asset.textures;
|
||||
//for (var i = 0; i < textures.length; i++) {
|
||||
// var tex = textures[i];
|
||||
// if (tex.name === name) {
|
||||
// return tex;
|
||||
// }
|
||||
//}
|
||||
var textures = this.asset.textures;
|
||||
for (var i = 0; i < textures.length; i++) {
|
||||
var texture = textures[i];
|
||||
var url = texture && texture.url;
|
||||
if (url.endsWith(line)) {
|
||||
var tex = new sp.SkeletonTexture({ width: texture.getPixelWidth(), height: texture.getPixelHeight() });
|
||||
tex.setRealTexture(texture);
|
||||
return tex;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
load: function (line) {
|
||||
var texture = this.getTexture(line);
|
||||
if (texture) {
|
||||
return texture;
|
||||
}
|
||||
else {
|
||||
cc.errorID(7506, line);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
unload: function (obj) {
|
||||
//page.rendererObject.release();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* !#en The skeleton data of spine.
|
||||
* !#zh Spine 的 骨骼数据。
|
||||
@@ -117,13 +75,6 @@ var SkeletonData = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
// Fallback to raw asset for JSB -------------------
|
||||
atlasUrl: {
|
||||
default: '',
|
||||
url: cc.RawAsset
|
||||
},
|
||||
// -------------------------------------------------
|
||||
|
||||
/**
|
||||
* @property {Texture2D[]} textures
|
||||
*/
|
||||
@@ -132,6 +83,15 @@ var SkeletonData = cc.Class({
|
||||
type: [cc.Texture2D]
|
||||
},
|
||||
|
||||
/**
|
||||
* @property {String[]} textureNames
|
||||
* @private
|
||||
*/
|
||||
textureNames: {
|
||||
default: [],
|
||||
type: [cc.String]
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* A scale can be specified on the JSON or binary loader which will scale the bone positions,
|
||||
@@ -199,7 +159,7 @@ var SkeletonData = cc.Class({
|
||||
}
|
||||
|
||||
|
||||
if ( !(this.textures && this.textures.length > 0) ) {
|
||||
if ( !(this.textures && this.textures.length > 0 && this.textureNames && this.textureNames.length > 0) ) {
|
||||
if ( !quiet ) {
|
||||
cc.errorID(7507, this.name);
|
||||
}
|
||||
@@ -259,6 +219,20 @@ var SkeletonData = cc.Class({
|
||||
|
||||
// PRIVATE
|
||||
|
||||
_getTexture: !CC_JSB && function (line) {
|
||||
var names = this.textureNames;
|
||||
for (var i = 0; i < names.length; i++) {
|
||||
if (names[i] === line) {
|
||||
var texture = this.textures[i];
|
||||
var tex = new sp.SkeletonTexture({ width: texture.getPixelWidth(), height: texture.getPixelHeight() });
|
||||
tex.setRealTexture(texture);
|
||||
return tex;
|
||||
}
|
||||
}
|
||||
cc.errorID(7506, line);
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method _getAtlas
|
||||
* @param {boolean} [quiet=false]
|
||||
@@ -277,8 +251,7 @@ var SkeletonData = cc.Class({
|
||||
return null;
|
||||
}
|
||||
|
||||
var loader = new TextureLoader(this);
|
||||
return this._atlasCache = new sp.spine.TextureAtlas(this.atlasText, loader.load.bind(loader));
|
||||
return this._atlasCache = new sp.spine.TextureAtlas(this.atlasText, this._getTexture.bind(this));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user