Android draw using SurfaceView and Thread

假装没事ソ 提交于 2019-11-29 06:35:38

well , as you can see on the image , you only drew the ball . instead , you need to re-drew a black background (or whatever that you wish) before each time you draw the ball.

alternatively , you can draw a black area only on the previous position , but you might have problems with it later , when you use more objects.

here's a nice sample, similar to what you do

Sorceri

A quick look and I would have to say you are just drawing on the same surface and never requesting your surfaceview to redraw itself. at the end of the finally block, in the IF Statement use: postInvalidate(); That should cause the surface view to redraw itself.

put this

public void onDraw(Canvas canvas){
   canvas.drawColor(Color.BLACK);

.....

}

See how i have done the pendulum simulation at http://som-itsolutions.blogspot.in/2012/06/android-graphics-and-animation-pendulum.html

You can clone the source code of this project from https://github.com/sommukhopadhyay/pendulumsimulation

[edit]The answer was wrong, but the comment was helpful so I'll leave this answer up:

Not the question you asked, but there is a problem in your code. In Android you are only allowed to write to the screen in the UI thread. This is the thread that runs all the Activity callbacks, etc. By writing to the screen from BallThread you are risking many odd failures in your program.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!