This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Is it possible to use Android GUI controls (buttons, labels, text fields, etc) on top of game graphics? For example; let's say I have an OpenGL drawn scene and want to popup a quit confirmation dialog? (the graphics a really on the box in that case)
What about rendering controls in the actual OpenGL or 2D graphics scene, for example a free floating button or text field in the middle of the screen.
The reason I'm asking is that in the desktop world, gaming engines usually have their own Game UI control libraries. Now, in Java2D/Swing it was possible to do some of this because the Swing controls are lightweight. I'm not sure if the Android controls are lightweight or not, so wondering if you guys know a bit about this (I realize the book is not about gaming, but hopefully you get what I mean).
Let me ask it another way, do you know if there's a way to draw a UI control in a view's onDraw method? Say in my 2D game scene I want to draw and animate buttons in the middle of the scene? Or is this done with some type of overlay mechanism?
All I know is OpenGL drawing occurs on a special view called GLSurfaceView which itself is derived from a View. Here is what the doc says about this view
Manages a surface, which is a special piece of memory that can be composited into the Android view system
Provides a dedicated drawing surface embedded inside of a view hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen
The surface is Z ordered so that it is behind the window holding its SurfaceView; the SurfaceView punches a hole in its window to allow its surface to be displayed. The view hierarchy will take care of correctly compositing with the Surface any siblings of the SurfaceView that would normally appear on top of it. This can be used to place overlays such as buttons on top of the Surface, though note however that it can have an impact on performance since a full alpha-blended composite will be performed each time the Surface changes.
It may be obliquely pointing to what you are refering to.
Actually that's good info. It sounds like for GL views they have something similar to Swing's layered panes. Will have to try it out.
For a 2D view, what I'm thinking is maybe I can pass the Canvas object to the onDraw method of a GUI control. I'm just getting started on Android so sorry, haven't tried out a bunch of these things, just trying to move from the Swing world :-)
Joined: May 11, 2011
I think you will find Android a good company then.
I am quite jealous of the EXTENSIVE graphics API in Android. Probably the most extensive of the Android APIs. You can see this from the sample programs that come with the android sdk.
However having spoiled by the web for so many years I haven't had a chance to cover the graphics API much as I will need to refresh the basic drawing principles on a canvas and using the drawable views etc. Not sure at all when I will get a chance to do that at this moment.