开发者

Displaying multiple copies of same external image in Actionscript 3.0

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜