permaculture playing cards*
The moose likes Android and the fly likes Is this a good approach? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Is this a good approach?" Watch "Is this a good approach?" New topic
Author

Is this a good approach?

Wizard Fox
Greenhorn

Joined: Oct 06, 2011
Posts: 1
Hi all.

I have made a "Hello World" animation (colorful circles bouncing around the screen) in order for learning and starting to get used with the Android ways.

I am a braziliam system analyst, Java certified, experienced, but a complete newbie in what concerns Android.

So, I would like comments about this approach for 2D annimation / games in Android, keeping a leach over an app Thread of my own.

In resume:

A run loop (in the View) that controls the animation, with a synchronized block that invokes a postInvalidate() and waits. So, when the
device triggers the onDraw event, it makes the drawing and, in other synchronized block, notifies the waiting Thread to proceed.

This way I keep a synchronization involving my Thread and the devide screen refreshes, and by testing this app in an actual device
(Android 2.2 API level 8) I reached about 85 to 90 frames per second, wich I think is framerate enough for my initial game developing purposes.

The other detail is an "init()" method, invoked when the onDraw first occurs. Then I know my app may initialize resources that depends on
device data (like screen width, height and so on), making it more device independent (by sizing initiated images according to the dimensions, for example).

Well, this is my trial of using a tradicional animation/game paradigm implementing a run loop (update / paint / sleep) with Android, but I don't know if this is the
best approach, or even if it is recommended at all.

Comments and info very appreciated here, thank you all very much.

ps. I know the code is rough, and that it may receive many improvements, but as I said, is just an "animation Hello World" to play around with Android
capabilities, feel the environment and put this approach into test.





 
 
subject: Is this a good approach?
 
Similar Threads
Bouncing balls
C++ish Address &
Please help with this program
advice on drawing a square wave pulse train
what is need of super() in the foolowing line of code?