Android - What classes to use for UI game development
I am trying to determine how to structure the code of a simple android game I am writing. I am focused on the UI portion. The behind the scenes portion (like a pause/restart/switching/etc) does not concern me. The Android demo games source code already do a great job with this.
Essentially my game will need a UI 开发者_开发百科with a series of objects on the screen (roughly 100 or 10x10) that the user can interact with. I need to supply an image for each object as well as implement the touch events and animation events for each object. What I am wondering is what type of class do I use for each object so that I can successfully implement these methods and how do I implement that particular class. Note that this game only executes on a user interaction with one of these objects, meaning I don't need a "real-time" implementation.
My research seems to point in the direction that each screen object needs to be a view object and that I need to place add each view object inside a viewgroup container. I then need to decide on a layout for the viewgroup, but I’m really not sure. Is this a viable approach or are there better alternatives?
I guess I am looking for design methodology more than anything. Thanks for the advice.
Read up on using SurfaceView, which provides a Canvas onto which you can easily draw objects (give your Objects a draw() method that takes a Canvas as an argument so that they can draw themselves onto it)/Bitmaps/shapes. Look at the sample code for the JetBoy game, that should get you started.
Each image/object would probably be an extended class of ImageView. Or just an ImageView if it's simple enough.
On your activity code, you can then attach onTouchListeners to these imageview to determine when the use is touching them.
You'll need to use SurfaceView as your container. You can then add your object image views to the surface view and you should be set for a good starting point.
精彩评论