![]()
|
|
Smartphone Game Programming Disclaimer
Smartphone programming is a big subject and I'm only going to deal with a very small subset of it, so it's important you know what will and won't be presented in these tutorials.
First, the purpose of the tutorials is to give anyone with a little programming experience, enough information to start writing their own Smartphone games. Everything I used in creating Flamethrower Carnage will at some point be covered. So if you want to write 2D games like Flamethrower Carnage, great.
On the other hand, I make no claim to being a great, or even good, C / C++ developer. So this tutorial isn't going to teach you how to write C. There are enough guides on the net about that. Moreover, the code I show you might be ugly, and it might well not be the best way to do something, but it will work. If on the other hand you know more C than I do, and spot an error or omission, why not email me and let me know. You'll get full credit on this page for any help or suggestions! Tutorial 1: installing the development environment Writing applications for Microsoft Smartphones couldn't be easier. OK, that's a lie. It could be lots easier.
Here's what you need to know to start with: The good news The good news is that all the tools you need for Smartphone programming are free for all purposes. That means that the programming environment, emulator and code samples are all available for free download and use, directly from Microsoft. The bad news
Well, there are several pieces of bad news.
Firstly, the downloads are enormous. You're going to need access to a broadband connection to download them.
Secondly, the tools allow you to write your Smartphone code in Embedded Visual C++. This can be complex and mind-bending stuff. If you want to program in Visual Basic (for instance), you're going to need Visual Studio .NET - and even then you can only write code for Windows Mobile 2003 devices. There is no support for .NET in Smartphone 2002 - and probably never will be.
These tutorials will deal only with Embedded Visual C++ (eVC), because the tools are free so anyone can have a go, whereas Visual Studio .NET costs serious money. Moreover, eVC is more flexible for Smartphone programming than .NET is - especially where games are concerned.
You're going to need Windows 2000 or Windows XP, too. This is the land of Microsoft, after all. You'll also need some disk space too - maybe a gigabyte or two.
What to download
Hope your download manager is a good one; you're going to need it to download these babies.
I recommend that you download the environments for both Smartphone 2002, and Windows Mobile 2003, and install them in that order. This way you can easily write code for one of the two platforms, then recompile it for the other platform. For reference, most compiled Smartphone 2002 code will run on Windows Mobile 2003. The reverse is not true - code compiled for Windows Mobile 2003 won't run on Smartphone 2002. Don't worry about all this too much - it'll be covered later in the tutorials.
Remember that these are all legitimate Microsoft downloads. It's worth remembering too that Microsoft has a whole load of information about these tools. Go to http://www.microsoft.com/windowsmobile/ for lots more information. Here are the links for the software you need to download:
updated! You might already have this installed if you're interested in Smartphones, but if not, the first thing you should download -and install - is Microsoft ActiveSync 3.7.1, here. It's a tiny 4Mb - well it's tiny compared to the other downloads...
1: 205Mb Embedded Visual C++ 3.0 for Smartphone 2002 - includes the all-important Software Development Kit (SDK) for Smartphone 2002
2: 220Mb Embedded Visual C++ 4.0 for Windows Mobile 2003 - strangely, this does not include the necessary SDK for Windows Mobile 2003.
3: 42Mb Service Pack 2 for eVC 4 The product key is the same for both eVC3 and eVC4, and you can find it at the bottom of this Microsoft page. Run the downloads in the order you downloaded them. That is to say, install ActiveSync first, then eVC3, then eVC4, then the eVC4 Service Pack. Make sure you reboot when the system asks you to - this isn't the sort of place where you can get away without rebooting. You're going to need plenty of disk space too.
updated!
Olivier emailed me to point out that if you have Norton Anti-Virus installed - and this may go for other anti-virus tools too - then you may get alerts when you install the Smartphone 2003 SDK. This is because the Smartphone 2003 SDK installation uses .VBS script files - which you may know are a typical virus infection route. As long as you downloaded the SDK from Microsoft's site, for instance using the links above, then you hav enothing to worry about. But you MUST allow the VBS scripts to execute otherwise the installation will fail. Check that your virus checker is set to prompt when VBS scripts run, not disable automatically. Then allow the SDK scripts to execute.
Thanks for the email, Olivier!
Microsoft eMbedded Visual Tools (which contains eMbedded Visual C++ 3.0)
Microsoft Windows SDK for Smartphone 2002
Microsoft eMbedded Visual C++ 4.0
Microsoft Smartphone 2003 SDK Testing the environment Now that everything's installed, we'll create a default project to make sure it's all working properly.
Firstly, start up eVC 3 (that's the Smartphone 2002 version; we'll check later on eVC 4 for Windows Mobile 2003).
Your system should respond with a splash screen; a few moments later, the "Microsoft eMbedded Visual C++" window will appear, with just-about everything greyed out because we haven't loaded a project.
Click File -> New. The system responds by presenting the "New" dialog box, which shows three tabs: Files, Projects and Workspaces. Make sure the Projects tab is selected, then choose "WCE Smartphone 2002 Application".
Enter a name (for example, TestProject1) into the Name box - you can't create the new project until you've done this. Now click the OK button.
After a brief pause, the system responds with the "WCE Smartphone Application - Step 1 of 1" box. The prompt asks you to choose between "an empty project", "a simple Windows CE application", or "a typical 'Hello World!' application". Guess which one we're going to choose.
Yes, that's right, select "A typical 'Hello World!' application" and click "Finish".
The system responds with some "New Project Information" about the files that will be automatically created for us: A standard "Hello World" application will be created for you targeting:
Win32 (WCE ARM)
Win32 (WCE x86)
Main: TestProject1.cpp
Resources: TestProject1.rc, resource.h, newres.h and TestProject1.ico Click the OK button on this window. The system responds by returning you to the main window, which is now titled
"TestProject1 - Microsoft eMbedded Visual C++".
At the top of the window, there should be a drop-down list which is set to "Win32(WCE ARM) Debug". This means that at present, eVC is set to produce code compatible with the ARM processor. This is good when you want to build compiled code that runs on a real Smartphone, but what we want to do is test out the emulator, to make sure it's working properly. So change the drop-down list to "Win32(WCE x86) Release". This means that the compiled code produced by eVC will run (under the emulator) on your PC. Now, from the Build menu, choose "Execute TestProject1.exe".
updated! MoDaCo's moo_ski_doo very kindly got in touch to point out that people who don't have TCP/IP running might not be able to get the emulator to work. Now, if you're reading this on-line, then there's no problem, because TCP/IP will be running. If, however, you're not connected to the internet, and also not connected to a LAN, then you might have problems. I quote from moo_ski_doo:
I’d advise people without a network connection to follow this guide to install a loopback adapter, which is some software which tricks the computer in to thinking it’s connected to a network [via this URL at] Microsoft. Thanks, moo! And thanks to JoelRae who confirmed that he had to use this and it "worked like a charm"...
The system responds by displaying a "Connecting" dialog box. At the same time, it starts the Smartphone 2002 emulator. The emulator will go through the normal phone boot sequence, and will eventually get to the Home screen.
Once it gets there, eVC will notice that the emulator has started up, and
prompts:
path:\ARMDbg\TestProject.exe This file does not exist. Do you want to build it? Click "Yes" - obviously. The system might now respond with: path:\ARMDbg\TestProject.exe Unable to locate remote output files on your device. Press OK to update the remote output files. Press Cancel to abort this operation. EVC will now lock up for five to ten seconds while it pushes the compiled code across to the emulator. Once it's managed to do so, it will automatically run the application on the emulator. At this point, eVC will start responding again. Call the "Smart Phone" emulator window to the front of yor screen, and you should now be able to see that the default project we built, is running on the emulated phone: Hooray! We've "written" and built our first Smartphone program. Now let's check that evc4 (for Windows Mobile 2003) is working properly, too. First, shut down ("Turn Off") the emulator, and exit eVC3. You can run both
eVC3 and eVC4 at the same time, but you can't run both the 2002 and 2003 emulators at the same time.
You might hit one of the bugs at this point - sometimes, eVC and the emulator don't shut down properly. . Hit CTRL-SHIFT-ESC to bring up the Windows Task Manager. Click the Processes tab, and make sure that "emulator.exe" and "EVC.exe" are NOT listed as running processes. If they are listed, then kill them off by selecting one, clicking "End Process", and clicking "Yes" in the "Task Manager Warning"
box. Repeat this until no instances of "emulator.exe" or "EVC.EXE" remain.thanks to JoelRae for pointing out that it's emulator.exe, not explorer.exe :-D
Now start eVC4 from the Start Menu. You'll find that things are very similar to eVC3; you need to carry out the same steps, namely:
1) File -> New
2) Select "WCE Smartphone 2003 Application", enter a project name in the "Name" box (for instance, TestProject2), and hit OK.
3) Choose "Hello World!" from the "WCE Smartphone 2003 Application - Step
1 of 1" dialog box, and hit Finish.
4) On the "New Project Information" dialog box, hit "OK".
5) Check that the drop-down list is set to "Win32 (WCE emulator) Release"
- if not, change it.
6) Choose Build -> Execute TestProject2. Wait a good few seconds until eVC stops responding and then starts responding again. Now call the emulator window to the foreground. You should be able to see the default application running in a very similar fashion to the Smartphone 2002 screenshot above.
The end! Well, the end of this tutorial, anyway.
We've covered where to get the Smartphone downloads from and how to install them. We've also looked at how to get a default project up-and-running, and how to run it under the emulator.
The next tutorial will deal with a few simple but essential things: how to change and add to the menu items in the default project, how to create a thread to run your game, and most importantly, how to set the icon that eVC gives to your application.
Help! Are you having problems with the above tutorial?
First off, try "getting out of the car, then getting back in again" - which is to say, reboot your PC then try again (yeah, I know...). The eVC development tools (both versions 3 and 4) are buggy and prone to errors like "Platform Manager failed" for no (apparent) reason. Many of these problems can be cleared with the aid of a simple reboot.
Having other problems? Why not email me and let me know what the problem is. I certainly can't guarantee I can help, but if I can, I will. If I can't help with a particular problem, I'll put a description of the problem here. Maybe some kind-hearted soul will mail me an answer or suggestion - if they do, I'll put it up alongside the original question.
Questions and Answers No questions have yet been submitted on this tutorial. There is no source code for this tutorial.
all content copyright unless otherwise stated source code may be used freely for any purpose |