[]drawTexture 画出来的数据会有以前的数据

private var iconSpr:Sprite;
private var htmlCanvas:HTMLCanvas;
private var texture:Texture;
private var xNum:int = 0;
private var yNum:int = 0;
private var img:Image;

public function TestView()
{
img = new Image("comp/lhjicon_5.png");

img.x = 640;
img.y = 320;

iconSpr = new Sprite();
iconSpr.width = 1280;
iconSpr.height = 640;
iconSpr.addChild(img);

btn.on(Event.CLICK,this,runGame1);
}

private function runGame1():void
{
xNum = Math.random()*7 - 3;
yNum = Math.random()*7 - 3;

Laya.timer.loop(20,this,onRun);
Laya.timer.frameLoop(10,this,refresh);
}

private function refresh():void
{
IconSpr.graphics.clear();
iconSpr.graphics.clear();

if(htmlCanvas)
htmlCanvas.clear();
htmlCanvas = iconSpr.drawToCanvas(iconSpr.width,iconSpr.height,0,0);

if(!texture)
texture = new Texture(htmlCanvas);
else
{
texture.destroy(true);
texture = new Texture(htmlCanvas);
}

IconSpr.graphics.drawTexture(texture);
}

private function onRun():void
{
img.x += xNum;
img.y += yNum;

if(img.x < 0 || img.x > (1280 - 156))
{
xNum = -xNum;
}

if(img.y < 0 || img.y > (640 - 156))
{
yNum = -yNum;
}
}
 
我要达到的效果是 只画出当前的位置 没有重影
1.png
已邀请:

kezhiyu

赞同来自: qian

因为你把上一次的 又 draw 到canvas。。。然后又生产成了 texture,那就会有上一次的数据

要回复问题请先

商务合作
商务合作