package
{
import starling.display.Image;
import starling.display.Sprite;
import starling.events.Event;
import starling.textures.Texture;
public class JustATest extends Sprite
{
[Embed(source="1.png")]
public static var A_Bitmap:Class;
private var t1:Texture;
private var img:Image;
private var oldImages:Array = [];
public function JustATest()
{
addEventListener(Event.ADDED_TO_STAGE,onAdd);
}
private function onAdd(e:Event):void
{
t1 = Texture.fromBitmap(new A_Bitmap(),false);
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
private function onEnterFrame(e:Event):void
{
//清理
for (var j:int = 0; j < oldImages.length; j++){
oldImages[j].visible = false;
var iii:Image = oldImages[j] as Image;
iii.texture.dispose();//如果注释这一句,显卡很快就会爆掉,所以,用完Texture.fromBitmap,在退出场景的时候,一定要dispose,否则无用的、重复的贴图,就会占满显卡。
}
oldImages = [];
//绘制
for (var i:int = 0; i < 10; i++){
img = new Image(Texture.fromBitmap(new A_Bitmap(),false));
oldImages.push(img);
img.x = Math.random()*(stage.stageWidth-img.width);
img.y = Math.random()*(stage.stageHeight-img.height);
addChild(img);
}
}
}
}
starling性能问题笔记(二)
最新推荐文章于 2019-06-14 03:46:58 发布