Tutorial
http://msdn.microsoft.com/en-us/library/hh413206(v=vs.88).aspx
![]() |
| Mars Invaders |
For reference, if you are planning on doing the tutorial yourself here's the exception. There is code in there to switch between accelerometer control and keyboard depending upon whether running on the emulator or a device, but in my own case I had to disable the checks and always use the accelerometer (which works in the emulator via the 3D phone drag). There may be a second exception, but I put it down to me missing something: at one point the tutorial said to make a change after an 'if' statement in the PlayerShip.Update routine but in the code I had created up to that point (and in fact beyond) there was no such 'if' statement, implying missing code. I copied the method contents from the tutorial source (it was longer) and it all worked.
The performance was more than acceptable, though obviously real devices will vary.
Coding games in C# is nice. I have my own C# game engines I've done in the past using GDI+ (there were reasons, honest) so this way of working was very familiar. I was especially pleased with the event-driven model of the game (Update and Draw events make things easy), and equally so with the way you can create a DrawableGameComponent-derived class and by simply adding it to the game's Components any instance of it is automatically enrolled and it's own equivalent events called. Simple concept, but neatly done.
![]() |
| Emulator |
One of the requirements of the devices (in order to be certified) is a hardware scaler, which works independently of the GPU and apparently has effectively zero performance impact. What it means in practice is that you pick a resolution (480x800 ideally) and code everything assuming that. The scaler automatically and at high quality scales the display output to the phone resolution and also scales the touch input so you can, quite literally, ignore the entire issue.
Incidentally, the scaler guarantees no change to the aspect ratio so if necessary black areas will be there, like letterbox widescreen.
So with minimal code the tutorial end result is an event-driven, object based Space Invaders clone with background image, starting screen, fleets of ships, missiles, scoring, multiple lives, background music (of a sort) and sound effects. Playable as a demo game, though by design not production standard, it was remarkably simple code - I'll definitely be looking at doing some of my own stuff for these phones.


0 comments:
Post a Comment