mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
Multi page atlas support for Flash and Starling.
http://www.esotericsoftware.com/forum/viewtopic.php?p=9409#p9409
This commit is contained in:
parent
71956544ba
commit
faa7c49627
@ -41,7 +41,7 @@ import spine.SkeletonJson;
|
||||
import spine.animation.AnimationStateData;
|
||||
import spine.atlas.Atlas;
|
||||
import spine.attachments.AtlasAttachmentLoader;
|
||||
import spine.flash.SingleTextureLoader;
|
||||
import spine.flash.FlashTextureLoader;
|
||||
import spine.flash.SkeletonAnimation;
|
||||
|
||||
[SWF(width = "640", height = "480", frameRate = "60", backgroundColor = "#dddddd")]
|
||||
@ -58,7 +58,7 @@ public class Main extends Sprite {
|
||||
private var skeleton:SkeletonAnimation;
|
||||
|
||||
public function Main () {
|
||||
var atlas:Atlas = new Atlas(new SpineboyAtlas(), new SingleTextureLoader(new SpineboyAtlasTexture()));
|
||||
var atlas:Atlas = new Atlas(new SpineboyAtlas(), new FlashTextureLoader(new SpineboyAtlasTexture()));
|
||||
var json:SkeletonJson = new SkeletonJson(new AtlasAttachmentLoader(atlas));
|
||||
var skeletonData:SkeletonData = json.readSkeletonData(new SpineboyJson());
|
||||
|
||||
|
||||
@ -39,23 +39,42 @@ import spine.atlas.AtlasPage;
|
||||
import spine.atlas.AtlasRegion;
|
||||
import spine.atlas.TextureLoader;
|
||||
|
||||
public class SingleTextureLoader implements TextureLoader {
|
||||
private var pageBitmapData:BitmapData;
|
||||
public class FlashTextureLoader implements TextureLoader {
|
||||
public var bitmapDatas:Object = {};
|
||||
public var singleBitmapData:BitmapData;
|
||||
|
||||
/** @param object A Bitmap or BitmapData. */
|
||||
public function SingleTextureLoader (object:*) {
|
||||
if (object is BitmapData)
|
||||
pageBitmapData = BitmapData(object);
|
||||
else if (object is Bitmap)
|
||||
pageBitmapData = Bitmap(object).bitmapData;
|
||||
else
|
||||
throw new ArgumentError("object must be a Bitmap or BitmapData.");
|
||||
/** @param bitmaps A Bitmap or BitmapData for an atlas that has only one page, or for a multi page atlas an object where the
|
||||
* key is the image path and the value is the Bitmap or BitmapData. */
|
||||
public function FlashTextureLoader (bitmaps:Object) {
|
||||
if (bitmaps is BitmapData) {
|
||||
singleBitmapData = BitmapData(bitmaps);
|
||||
return;
|
||||
}
|
||||
if (bitmaps is Bitmap) {
|
||||
singleBitmapData = Bitmap(bitmaps).bitmapData;
|
||||
return;
|
||||
}
|
||||
|
||||
for (var path:* in bitmaps) {
|
||||
var object:* = bitmaps[path];
|
||||
var bitmapData:BitmapData;
|
||||
if (object is BitmapData)
|
||||
bitmapData = BitmapData(object);
|
||||
else if (object is Bitmap)
|
||||
bitmapData = Bitmap(object).bitmapData;
|
||||
else
|
||||
throw new ArgumentError("Object for path \"" + path + "\" must be a Bitmap or BitmapData: " + object);
|
||||
bitmapDatas[path] = bitmapData;
|
||||
}
|
||||
}
|
||||
|
||||
public function loadPage (page:AtlasPage, path:String) : void {
|
||||
page.rendererObject = pageBitmapData;
|
||||
page.width = pageBitmapData.width;
|
||||
page.height = pageBitmapData.height;
|
||||
var bitmapData:BitmapData = singleBitmapData || bitmapDatas[path];
|
||||
if (!bitmapData)
|
||||
throw new ArgumentError("BitmapData not found with name: " + path);
|
||||
page.rendererObject = bitmapData;
|
||||
page.width = bitmapData.width;
|
||||
page.height = bitmapData.height;
|
||||
}
|
||||
|
||||
public function loadRegion (region:AtlasRegion) : void {
|
||||
@ -6,7 +6,7 @@ import spine.SkeletonJson;
|
||||
import spine.animation.AnimationStateData;
|
||||
import spine.atlas.Atlas;
|
||||
import spine.attachments.AtlasAttachmentLoader;
|
||||
import spine.starling.SingleTextureLoader;
|
||||
import spine.starling.StarlingTextureLoader;
|
||||
import spine.starling.SkeletonAnimation;
|
||||
import spine.starling.StarlingAtlasAttachmentLoader;
|
||||
|
||||
@ -31,7 +31,7 @@ public class AtlasExample extends Sprite {
|
||||
private var skeleton:SkeletonAnimation;
|
||||
|
||||
public function AtlasExample () {
|
||||
var atlas:Atlas = new Atlas(new SpineboyAtlasFile(), new SingleTextureLoader(new SpineboyAtlasTexture()));
|
||||
var atlas:Atlas = new Atlas(new SpineboyAtlasFile(), new StarlingTextureLoader(new SpineboyAtlasTexture()));
|
||||
var json:SkeletonJson = new SkeletonJson(new AtlasAttachmentLoader(atlas));
|
||||
var skeletonData:SkeletonData = json.readSkeletonData(new SpineboyJson());
|
||||
|
||||
|
||||
@ -44,23 +44,42 @@ import spine.atlas.TextureLoader;
|
||||
import starling.textures.SubTexture;
|
||||
import starling.textures.Texture;
|
||||
|
||||
public class SingleTextureLoader implements TextureLoader {
|
||||
private var pageBitmapData:BitmapData;
|
||||
|
||||
/** @param object A Bitmap or BitmapData. */
|
||||
public function SingleTextureLoader (object:*) {
|
||||
if (object is BitmapData)
|
||||
pageBitmapData = BitmapData(object);
|
||||
else if (object is Bitmap)
|
||||
pageBitmapData = Bitmap(object).bitmapData;
|
||||
else
|
||||
throw new ArgumentError("object must be a Bitmap or BitmapData.");
|
||||
public class StarlingTextureLoader implements TextureLoader {
|
||||
public var bitmapDatas:Object = {};
|
||||
public var singleBitmapData:BitmapData;
|
||||
|
||||
/** @param bitmaps A Bitmap or BitmapData for an atlas that has only one page, or for a multi page atlas an object where the
|
||||
* key is the image path and the value is the Bitmap or BitmapData. */
|
||||
public function StarlingTextureLoader (bitmaps:Object) {
|
||||
if (bitmaps is BitmapData) {
|
||||
singleBitmapData = BitmapData(bitmaps);
|
||||
return;
|
||||
}
|
||||
if (bitmaps is Bitmap) {
|
||||
singleBitmapData = Bitmap(bitmaps).bitmapData;
|
||||
return;
|
||||
}
|
||||
|
||||
for (var path:* in bitmaps) {
|
||||
var object:* = bitmaps[path];
|
||||
var bitmapData:BitmapData;
|
||||
if (object is BitmapData)
|
||||
bitmapData = BitmapData(object);
|
||||
else if (object is Bitmap)
|
||||
bitmapData = Bitmap(object).bitmapData;
|
||||
else
|
||||
throw new ArgumentError("Object for path \"" + path + "\" must be a Bitmap or BitmapData: " + object);
|
||||
bitmapDatas[path] = bitmapData;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function loadPage (page:AtlasPage, path:String) : void {
|
||||
page.rendererObject = Texture.fromBitmapData(pageBitmapData);
|
||||
page.width = pageBitmapData.width;
|
||||
page.height = pageBitmapData.height;
|
||||
var bitmapData:BitmapData = singleBitmapData || bitmapDatas[path];
|
||||
if (!bitmapData)
|
||||
throw new ArgumentError("BitmapData not found with name: " + path);
|
||||
page.rendererObject = Texture.fromBitmapData(bitmapData);
|
||||
page.width = bitmapData.width;
|
||||
page.height = bitmapData.height;
|
||||
}
|
||||
|
||||
public function loadRegion (region:AtlasRegion) : void {
|
||||
@ -78,9 +97,9 @@ public class SingleTextureLoader implements TextureLoader {
|
||||
}
|
||||
region.rendererObject = image;
|
||||
}
|
||||
|
||||
|
||||
public function unloadPage (page:AtlasPage) : void {
|
||||
BitmapData(pageBitmapData).dispose();
|
||||
BitmapData(page.rendererObject).dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user