So the game works, it does everything it needs to in terms of playability. OK the difficulty needs balancing, but I'm happy to say that's coded in such a way that they take only seconds to write (play testing is the awkward thing). So all of my screen transitions up to the game work, the main menu, the pause menu (placeholder graphics, but meh) all good. All I need is a local high score screen and I'm pretty much good to go.
So as ever I think about the components needed to do it correctly:
- SavedPreference object for holding the score? Check.
- Sorting function to determine which high score has been achieved? Check
- Text box for the player to type their name? ...
And then, this morning, a breakthrough! A new view up on screen (floating, as it were, on top of the main screen) from which it will be simple to add one of the Android widgets. Except, well it wasn't. Again. And now the errors that were being thrown were miles out of my comfort zone, null pointer exceptions are fine, but these errors felt like dissertations on multi-threading.
Back to the internet, to the Android documentation, to stackoverflow.com. After a little while trying to find similar issues, I new I needed to add a looper and a handler. But how do they talk? What exactly do I need to do?
Finally out of desperation I took the first part of the code and just stuck it in the one thread I know I have running:
Looper.prepare();
//Some other stuff
Looper.loop();And it worked!
I'm still not entirely sure how the handling is being done, or if I'm just being hideously obtuse. For now though I'm just going to take it as a win, and leave the thinking for when I'm more likely to cope with it.
*For those interested in this sort of thing, the game framework is based on Mario Zechner's book 'beginning android games' which I discovered through the tutorials at kilobolt.com. The framework uses a surface view to render all the goings on to a single bitmap, which is then scaled and drawn to the resolution of the device.
This works brilliantly but adding additional 'View' components isn't the simplest thing in the world, at least to a novice like me.
No comments:
Post a Comment