So I have a thread that is instantiated inside a view. The thread should call postInvalidate()
to redraw the screen every 16 milliseconds (60fps). The screen never redraws itself, though. It just remains blank. What am I doing wrong? Code is below:
public class DrawingView extends View {
private Paint paint;
private GraphicsLoop gThread;
public DrawingView(Context context, AttributeSet attrs) {
super(context, attrs);
paint = new Paint();
gThread = new GraphicsLoop();
gThread.start();
}
@Override
protected void onDraw(Canvas canvas) {
// Draw Stuff
}
}
Thread:
public class GraphicsLoop extends Thread {
private long frameTime;
GraphicsLoop(){
}
@Override
public void run() {
while(true) {
long frameTimeDelta = System.currentTimeMillis() - frameTime;
if (frameTimeDelta > 16) {
frameTime = System.currentTimeMillis();
postInvalidate();
}
}
}
@Override
public void start ()
{
frameTime = System.currentTimeMillis();
}
}