• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Is this a good approach?

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

    Bookmark Topic Watch Topic
  • New Topic