Refresh a view every x milliseconds

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Refresh a view every x milliseconds

Postby Risike » Sat May 23, 2009 1:19 pm

Sorry for my bad english.

I'm trying to create a game.

I have a GameView which extends View. I would like this view is redrawn every 1/60 seconds like with SDL for example.
I created a Thread with a run method with a this :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. while(true){
  2.  
  3.     myGameView.invalidate();
  4.  
  5.     Thread.sleep(x); // 1/60 second
  6.  
  7. }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


But the application crash when I start this Thread...

How can I do this ?
Risike
Freshman
Freshman
 
Posts: 3
Joined: Wed May 13, 2009 1:23 pm

Top

Postby doubleslash » Sat Jul 18, 2009 10:16 pm

You cannot invalidate a view from a non UI thread. Use a handler.
doubleslash
Developer
Developer
 
Posts: 30
Joined: Fri Feb 13, 2009 6:05 am

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest