mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[haxe] AssetsTextureLoader is now StarlingTextureLoader, remove TextureAtlas.from, change SkeletonData.from to not use OpenFL Assets.
This commit is contained in:
parent
bb3bd3ad40
commit
eed1a3e30a
@ -27,20 +27,22 @@
|
||||
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
import openfl.utils.Assets;
|
||||
import spine.SkeletonData;
|
||||
import spine.animation.AnimationStateData;
|
||||
import spine.atlas.TextureAtlas;
|
||||
import spine.starling.SkeletonSprite;
|
||||
import spine.starling.StarlingTextureLoader;
|
||||
import starling.core.Starling;
|
||||
import starling.events.TouchEvent;
|
||||
import starling.events.TouchPhase;
|
||||
|
||||
class BasicExample extends Scene {
|
||||
var loadBinary = false;
|
||||
var loadBinary = true;
|
||||
|
||||
public function load():Void {
|
||||
var atlas = TextureAtlas.fromAssets("assets/raptor.atlas");
|
||||
var skeletondata = SkeletonData.fromAssets("assets/raptor-pro" + (loadBinary ? ".skel" : ".json"), atlas);
|
||||
var atlas = new TextureAtlas(Assets.getText("assets/raptor.atlas"), new StarlingTextureLoader("assets/raptor-pro.atlas"));
|
||||
var skeletondata = SkeletonData.from(loadBinary ? Assets.getBytes("assets/raptor-pro.skel") : Assets.getText("assets/raptor-pro.json"), atlas);
|
||||
var animationStateData = new AnimationStateData(skeletondata);
|
||||
animationStateData.defaultMix = 0.25;
|
||||
|
||||
|
||||
@ -27,10 +27,12 @@
|
||||
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
import openfl.utils.Assets;
|
||||
import spine.SkeletonData;
|
||||
import spine.animation.AnimationStateData;
|
||||
import spine.atlas.TextureAtlas;
|
||||
import spine.starling.SkeletonSprite;
|
||||
import spine.starling.StarlingTextureLoader;
|
||||
import starling.core.Starling;
|
||||
import starling.events.TouchEvent;
|
||||
import starling.events.TouchPhase;
|
||||
@ -39,8 +41,8 @@ class SequenceExample extends Scene {
|
||||
var loadBinary = false;
|
||||
|
||||
public function load():Void {
|
||||
var atlas = TextureAtlas.fromAssets("assets/dragon.atlas");
|
||||
var skeletondata = SkeletonData.fromAssets("assets/dragon-ess" + (loadBinary ? ".skel" : ".json"), atlas);
|
||||
var atlas = new TextureAtlas(Assets.getText("assets/dragon.atlas"), new StarlingTextureLoader("assets/dragon.atlas"));
|
||||
var skeletondata = SkeletonData.from(loadBinary ? Assets.getBytes("assets/dragon-ess.skel") : Assets.getText("assets/dragon-ess.json"), atlas);
|
||||
var animationStateData = new AnimationStateData(skeletondata);
|
||||
animationStateData.defaultMix = 0.25;
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
|
||||
package spine;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import openfl.utils.Assets;
|
||||
import spine.animation.Animation;
|
||||
import spine.atlas.TextureAtlas;
|
||||
@ -57,19 +58,17 @@ class SkeletonData {
|
||||
public var imagesPath:String;
|
||||
public var audioPath:String;
|
||||
|
||||
public static function fromAssets(path:String, atlas:TextureAtlas, scale:Float = 1.0):SkeletonData {
|
||||
if (StringTools.endsWith(path, ".skel")) {
|
||||
var byteData = Assets.getBytes(path);
|
||||
public static function from(data:Dynamic, atlas:TextureAtlas, scale:Float = 1.0):SkeletonData {
|
||||
if (Std.isOfType(data, Bytes)) {
|
||||
var loader = new SkeletonBinary(new AtlasAttachmentLoader(atlas));
|
||||
loader.scale = scale;
|
||||
return loader.readSkeletonData(byteData);
|
||||
} else if (StringTools.endsWith(path, ".json")) {
|
||||
var jsonData = Assets.getText(path);
|
||||
return loader.readSkeletonData(cast(data, Bytes));
|
||||
} else if (Std.isOfType(data, String)) {
|
||||
var loader = new SkeletonJson(new AtlasAttachmentLoader(atlas));
|
||||
loader.scale = scale;
|
||||
return loader.readSkeletonData(jsonData);
|
||||
return loader.readSkeletonData(cast(data, String));
|
||||
} else {
|
||||
throw new SpineException("Path of skeleton data file must end with .json or .skel");
|
||||
throw new SpineException("Data must either be a String (.json) or Bytes (.skel) instance.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -37,17 +37,6 @@ class TextureAtlas {
|
||||
private var regions = new Array<TextureAtlasRegion>();
|
||||
private var textureLoader:TextureLoader;
|
||||
|
||||
public static function fromAssets(path:String) {
|
||||
var basePath = "";
|
||||
var slashIndex = path.lastIndexOf("/");
|
||||
if (slashIndex != -1) {
|
||||
basePath = path.substring(0, slashIndex);
|
||||
}
|
||||
|
||||
var textureLoader = new AssetsTextureLoader(basePath);
|
||||
return new TextureAtlas(Assets.getText(path), textureLoader);
|
||||
}
|
||||
|
||||
/** @param object A String or ByteArray. */
|
||||
public function new(atlasText:String, textureLoader:TextureLoader) {
|
||||
if (atlasText == null) {
|
||||
|
||||
@ -27,18 +27,22 @@
|
||||
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
package spine.atlas;
|
||||
package spine.starling;
|
||||
|
||||
import starling.textures.Texture;
|
||||
import spine.atlas.TextureAtlasRegion;
|
||||
import spine.atlas.TextureAtlasPage;
|
||||
import spine.atlas.TextureLoader;
|
||||
|
||||
class AssetsTextureLoader implements TextureLoader {
|
||||
class StarlingTextureLoader implements TextureLoader {
|
||||
private var basePath:String;
|
||||
|
||||
public function new(basePath:String) {
|
||||
this.basePath = basePath;
|
||||
public function new(atlasPath:String) {
|
||||
basePath = "";
|
||||
var slashIndex = atlasPath.lastIndexOf("/");
|
||||
if (slashIndex != -1) {
|
||||
basePath = atlasPath.substring(0, slashIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public function loadPage(page:TextureAtlasPage, path:String) {
|
||||
Loading…
x
Reference in New Issue
Block a user