开发者

Displaying multiple copies of same external image in Actionscript 3.0

开发者 https://www.devze.com 2022-12-10 22:01 出处:网络
I know I can load and display an external image like s开发者_JS百科o: var loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);

I know I can load and display an external image like s开发者_JS百科o:

var loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
var container = new Sprite();
container.addChild(loader);
try {
    loader.load(new URLRequest("http://www.google.com/intl/en_ALL/images/logo.gif"));
} catch (e:Error) {
    trace("oh my god");
}

But what if I want to use such an image as a sprite in my game, meaning there could be a hundred copies of the same image. Should I just call loader.load a hundred times and trust that my cache is really clever, or is there some way to get a copy of the already loaded image to display in a different place?


You can get a reference of the Loader's BitmapData, and instantiate as many Bitmaps as you want with it:

var bmp:BitmapData=Bitmap(Loader.content).bitmapData;
var bitmap1:Bitmap=new Bitmap(bmp);
var bitmap2:Bitmap=new Bitmap(bmp);
0

精彩评论

暂无评论...
验证码 换一张
取 消