I've created an Android game based on this tutorial. I have a lot of development experience, but these are my first steps into Java and a mobile platform.
The game is created as a single activity with everything drawn on a SurfaceView and 'Screens' specified that break everything up. I have no xml layout. The onCreate for the main class is the best place to see how it's set up. The AndroidFastRenderView extends SurfaceView.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
int frameBufferWidth = isPortrait ? 480 : 800;
int frameBufferHeight = isPortrait ? 800 : 480;
Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth,
frameBufferHeight, Config.RGB_565);
float scaleX = (float) frameBufferWidth
/ getWindowManager().getDefaultDisplay().getWidth();
float scaleY = (float) frameBufferHeight
/ getWindowManager().getDefaultDisplay().getHeight();
renderView = new AndroidFastRenderView(this, frameBuffer);
graphics = new AndroidGraphics(getAssets(), frameBuffer);
fileIO = new AndroidFileIO(this);
audio = new AndroidAudio(this);
input = new AndroidInput(this, renderView, scaleX, scaleY);
screen = getInitScreen();
setContentView(renderView);
}
I'm looking for a way to enable to user to enter a name for the high scores table - which I thought would be simple. I'm really struggling with the best way to receive keyboard input. What's my best option here? I'm assuming there's some way I can create a custom edit that I can draw on my the surface view myself and receive keyboard input that way. However, I'm guessing displaying an EditText over the top of the surface view will be easier - but I can't for the life of me work out how to do it. I've tried numerous methods that I've found through Google and SO but can't seem to get any of them to work.
Advice and sample code would be much appreciated.
Many thanks