我正在寻找一种从线程调用 invalidate 方法的方法。基本上我想做的是onDraw
从DrawThread
.
protected void onDraw(Canvas canvas) {
// Drawing commands go here
canvas.drawArc(oval, strt, arc, true, cPaint);
while(i<90)
{
canvas.drawText(z,300,300, tPaint);
break;
}
class DrawThread extends Thread
{
GameView a;
Canvas canvas;
DrawThread(GameView a)
{
this.a=a;
start();
}
public void run()
{
a.flag2=true;
while(a.flag2)
{
try
{
sleep(200);
}
catch(Exception e)
{
}
if(!a.flag1)
{
a.x+=10;
if(!a.flag3)
{
a.strt-=15;
a.arc+=15;
}
else
{
a.strt+=15;
a.arc-=15;
}
}
if(a.flag1)
{
a.x-=10;
if(!a.flag3)
a.arc+=15;
if(a.flag3)
a.arc-=15;
}
if(a.x==600)
{
a.y+=60;
a.flag1=true;
a.strt=180;
a.arc=315;
}
if(a.x==30)
{
a.y+=60;
a.flag1=false;
a.strt=45;
a.arc=315;
}
if(a.y>=600)
{
a.y=60;
}
if(a.strt==0 || a.arc==360)
{
a.flag3=true;
}
if(a.strt==45 || a.arc==315)
{
a.flag3=false;
}
if(a.n1==a.x&&a.n2==a.y)
{
a.i+=1;
a.n1 = Math.random()*10;
a.n2 = Math.random()*60;
}
a.invalidate();
}
}
}