mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-22 02:06:03 +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.animation.AnimationStateData;
|
||||||
import spine.atlas.Atlas;
|
import spine.atlas.Atlas;
|
||||||
import spine.attachments.AtlasAttachmentLoader;
|
import spine.attachments.AtlasAttachmentLoader;
|
||||||
import spine.flash.SingleTextureLoader;
|
import spine.flash.FlashTextureLoader;
|
||||||
import spine.flash.SkeletonAnimation;
|
import spine.flash.SkeletonAnimation;
|
||||||
|
|
||||||
[SWF(width = "640", height = "480", frameRate = "60", backgroundColor = "#dddddd")]
|
[SWF(width = "640", height = "480", frameRate = "60", backgroundColor = "#dddddd")]
|
||||||
@ -58,7 +58,7 @@ public class Main extends Sprite {
|
|||||||
private var skeleton:SkeletonAnimation;
|
private var skeleton:SkeletonAnimation;
|
||||||
|
|
||||||
public function Main () {
|
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 json:SkeletonJson = new SkeletonJson(new AtlasAttachmentLoader(atlas));
|
||||||
var skeletonData:SkeletonData = json.readSkeletonData(new SpineboyJson());
|
var skeletonData:SkeletonData = json.readSkeletonData(new SpineboyJson());
|
||||||
|
|
||||||
|
|||||||
@ -39,23 +39,42 @@ import spine.atlas.AtlasPage;
|
|||||||
import spine.atlas.AtlasRegion;
|
import spine.atlas.AtlasRegion;
|
||||||
import spine.atlas.TextureLoader;
|
import spine.atlas.TextureLoader;
|
||||||
|
|
||||||
public class SingleTextureLoader implements TextureLoader {
|
public class FlashTextureLoader implements TextureLoader {
|
||||||
private var pageBitmapData:BitmapData;
|
public var bitmapDatas:Object = {};
|
||||||
|
public var singleBitmapData:BitmapData;
|
||||||
|
|
||||||
/** @param object 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
|
||||||
public function SingleTextureLoader (object:*) {
|
* 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)
|
if (object is BitmapData)
|
||||||
pageBitmapData = BitmapData(object);
|
bitmapData = BitmapData(object);
|
||||||
else if (object is Bitmap)
|
else if (object is Bitmap)
|
||||||
pageBitmapData = Bitmap(object).bitmapData;
|
bitmapData = Bitmap(object).bitmapData;
|
||||||
else
|
else
|
||||||
throw new ArgumentError("object must be a Bitmap or BitmapData.");
|
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 {
|
public function loadPage (page:AtlasPage, path:String) : void {
|
||||||
page.rendererObject = pageBitmapData;
|
var bitmapData:BitmapData = singleBitmapData || bitmapDatas[path];
|
||||||
page.width = pageBitmapData.width;
|
if (!bitmapData)
|
||||||
page.height = pageBitmapData.height;
|
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 {
|
public function loadRegion (region:AtlasRegion) : void {
|
||||||
@ -6,7 +6,7 @@ import spine.SkeletonJson;
|
|||||||
import spine.animation.AnimationStateData;
|
import spine.animation.AnimationStateData;
|
||||||
import spine.atlas.Atlas;
|
import spine.atlas.Atlas;
|
||||||
import spine.attachments.AtlasAttachmentLoader;
|
import spine.attachments.AtlasAttachmentLoader;
|
||||||
import spine.starling.SingleTextureLoader;
|
import spine.starling.StarlingTextureLoader;
|
||||||
import spine.starling.SkeletonAnimation;
|
import spine.starling.SkeletonAnimation;
|
||||||
import spine.starling.StarlingAtlasAttachmentLoader;
|
import spine.starling.StarlingAtlasAttachmentLoader;
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ public class AtlasExample extends Sprite {
|
|||||||
private var skeleton:SkeletonAnimation;
|
private var skeleton:SkeletonAnimation;
|
||||||
|
|
||||||
public function AtlasExample () {
|
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 json:SkeletonJson = new SkeletonJson(new AtlasAttachmentLoader(atlas));
|
||||||
var skeletonData:SkeletonData = json.readSkeletonData(new SpineboyJson());
|
var skeletonData:SkeletonData = json.readSkeletonData(new SpineboyJson());
|
||||||
|
|
||||||
|
|||||||
@ -44,23 +44,42 @@ import spine.atlas.TextureLoader;
|
|||||||
import starling.textures.SubTexture;
|
import starling.textures.SubTexture;
|
||||||
import starling.textures.Texture;
|
import starling.textures.Texture;
|
||||||
|
|
||||||
public class SingleTextureLoader implements TextureLoader {
|
public class StarlingTextureLoader implements TextureLoader {
|
||||||
private var pageBitmapData:BitmapData;
|
public var bitmapDatas:Object = {};
|
||||||
|
public var singleBitmapData:BitmapData;
|
||||||
|
|
||||||
/** @param object 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
|
||||||
public function SingleTextureLoader (object:*) {
|
* 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)
|
if (object is BitmapData)
|
||||||
pageBitmapData = BitmapData(object);
|
bitmapData = BitmapData(object);
|
||||||
else if (object is Bitmap)
|
else if (object is Bitmap)
|
||||||
pageBitmapData = Bitmap(object).bitmapData;
|
bitmapData = Bitmap(object).bitmapData;
|
||||||
else
|
else
|
||||||
throw new ArgumentError("object must be a Bitmap or BitmapData.");
|
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 {
|
public function loadPage (page:AtlasPage, path:String) : void {
|
||||||
page.rendererObject = Texture.fromBitmapData(pageBitmapData);
|
var bitmapData:BitmapData = singleBitmapData || bitmapDatas[path];
|
||||||
page.width = pageBitmapData.width;
|
if (!bitmapData)
|
||||||
page.height = pageBitmapData.height;
|
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 {
|
public function loadRegion (region:AtlasRegion) : void {
|
||||||
@ -80,7 +99,7 @@ public class SingleTextureLoader implements TextureLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function unloadPage (page:AtlasPage) : void {
|
public function unloadPage (page:AtlasPage) : void {
|
||||||
BitmapData(pageBitmapData).dispose();
|
BitmapData(page.rendererObject).dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user