Starling Asset Manager by

28
Feb
0


package
{
import flash.display.Bitmap;
import flash.utils.Dictionary;

import starling.textures.Texture;
import starling.textures.TextureAtlas;

public class Assets
{
[Embed(source="../system/Blackground.jpg")]
public static const Blackground:Class;

[Embed(source="../assets/audio/sound1.mp3")]
public static const sound1:Class;

private static var gameTextureAtlas:TextureAtlas;

[Embed(source="../assets/textures/atlas.png")]
public static const atlasTexture:Class;

[Embed(source="../assets/textures/atlas.xml", mimeType="application/octet-stream")]
public static const atlasXML:Class;

public static function getAtlas():TextureAtlas
{
if (gameTextureAtlas == null)
{
var texture:Texture = getTexture("atlasTexture");
var xml:XML = XML(new atlasXML());
gameTextureAtlas = new TextureAtlas(texture, xml);
}
return gameTextureAtlas;
}

private static var gameTextures:Dictionary = new Dictionary();

public static function getTexture(name:String):Texture
{
if (gameTextures[name] == undefined)
{
var bitmap:Bitmap = new Assets[name]();
gameTextures[name] = Texture.fromBitmap(bitmap);
}
return gameTextures[name];
}
}
}


import starling.utils.AssetManager;
import starling.display.Sprite;
import starling.display.Image;
import flash.media.Sound;

private static var sAssets:AssetManager;
public function Main() extends Sprite
{
sAssets = new AssetManager();

//Add Texture
sAssets.addTexture("nameBlackground",Assets.getTexture("Blackground"));
//Add Atlas
sAssets.addTextureAtlas("atlas1",Assets.getAtlas());
//Add Sound
sAssets.addSound("sound1",new Assets.sound1() as Sound);

}
public function exampleUse():void
{
//Texture
var img:Image = new Image( assets.getTexture("nameBlackground"));
this.addChild(img);
//Atlast
var mc:MovieClip = new MovieClip( assets.getTextureAtlas("atlas1").getTextures("heroAttack"),12);
Starling.juggler.add(mc);//For sprite to play animation
this.addChild(mc);
//Sound
var s1:Sound = assets.getSound("sound1");
s1.play(0,1);
}
public static function get assets():AssetManager { return sAssets; }

Enjoy this article?

Consider subscribing to our RSS feed!

ไม่มีความเห็น

ยังไม่มีความเห็น

ใส่ความเห็น

RSS feed for comments on this post

กู้เงิน | เศรษฐกิจพอเพียง | สินเชื่อบุคคล | สมัครบัตรกดเงินสด | สินเชื่อ | เงินกู้ด่วน | ยืมเงินทรูมูฟ | เงินด่วนนอกระบบ