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; }

ตรวจสอบการใช้เมมโมรี่ของโปรเจค by

31
Jan
0

Flash profile perspective จะแสดง Package และ Memory ที่ใช้ให้ดู
ถ้าโปรแกรมใช้แรมมากเกินไปแล้วอยากรู้ว่าเป็นแพคเกจไหนที่ใช้แรมเยอะ ก็สามารถใช้ Flash profile ตรวจสอบได้

 เราชนะรอบ 4 | ยืมเงิน 3000 ด่วน | แอพกู้เงิน | แอพเงินด่วน | สินเชื่อออนไลน์อนุมัติทันที | Site Map | กู้เงินก้อน | กระเป๋าตัง | thisshop และ ยืมเงินฉุกเฉิน 5000 ด่วน