Windows Phone

How fast can I get up and running with Windows Phone game development?

Posted by admin on March 09, 2012
Development, Games, PC, Windows Phone / 1 Comment

I was asked the other day by a colleague how easy it would be to start developing a game for Windows Phone from scratch. After explaining him that developing a game for Windows Phone essentially means developing a game for Windows 7, Windows 8 and XBox 360 at the same time, I decided not to describe how easy it is but to actually show him. I also timed myself.  He had seen MonsterUp on the web, and was curious how it would be possible to simulate gravity , so the challenge was to make a ball bounce on the screen. I already had Visual Studio and XNA installed on my computer, but if you want to follow this and see how easy it is by yourself, you can download the free tools here. With a simple installation you will have everything you need including a free version of Visual Studio and a phone emulator. You can use these tools to develop for Windows Phone, XBOX 360 and Windows with little or no changes to the code.

So back to our bouncing ball tutorial. Consider this a “Hello World” for game development in XNA and Windows Phone. I guess I should mention that knowledge of Object Oriented programming is required here as well as some C, C++ or C# knowledge. We use C# for XNA.

Launch Visual Studio and choose to create a new Windows Game (File->New->Project). Name it whatever you want. I named mine “Gravity”.

Download a ball texture. I have one here for your convenience. Put it inside the Content directory that exists in your solution directory (which you created before). Drag and drop it on the Content section, in the Solution explorer of your solution. Your solution explorer should look like that:

If you click on the ball.png you will see that it has been assigned an automatic asset name “ball”. This is how we will recognize it when we load it in the game.

Now double click on Game1.cs on the Solution Explorer. This is the main game file which is automatically created for you. In here, there are a few important functions, which are also created automatically for you. One of them is called “Update”. This is called automatically and as fast as possible by XNA. Another is called “Draw”. Also called automatically, but depending on how heavy your game is, it may skip its run (in the default configuration) if the system it runs on cannot handle the load. This is called frame skipping. The important thing is that within the Update function you update the game logic (sprite movements, AI etc.) while in the Draw function you … well… draw stuff on the screen :)

Anyway, back to our ball thing. After “SpriteBatch spriteBatch” near the beginning of the file, add the following lines:

Texture2D ballTex;
Vector2 ballPosition;
Vector2 ballVelocity;

The first one creates an object which holds graphics (or texture) data. The other two are Vector2 objects, which essentially holds two float numbers. We will use the Vector2 objects to hold the position and velocity of the ball (duh).

In the LoadContent function (which is called once in the beginning of the game to load stuff) add the following line (after spriteBatch = new SpriteBatch(GraphicsDevice);)

ballTex = Content.Load<Texture2D>(“ball”);

With this small line, you have actually loaded the ball texture in the ballTex object. The Content object handles the loading depending on the file type (in this case, a .png file is loaded on a Texture2D object).

In the Update function, before the base.Update(gameTime) add the following lines:

ballPosition += ballVelocity;
ballVelocity.Y += 0.1f;
if (ballPosition.Y > 100)
{

    ballPosition.Y = 100;
     ballVelocity = -ballVelocity;
}

These lines update the ballPosition (by adding a Vector2 to another), simulates gravity (by adding a float to the Y component of the velocity – so the gravity pulls the ball towards the bottom of the screen) and also handles bouncing (if the ball moves beyond 100, reverse the ballVelocity and return the ball to the “ground”).

Finally, in the Draw function, add these lines before base.Draw(gameTime):

spriteBatch.Begin();
spriteBatch.Draw(ballTex, ballPosition, Color.White);
spriteBatch.End();

I’ve also changed the background color to Black, but this is optional.

Believe it or not, we are done! With 12 lines of code, we have a perfectly bouncing ball. Not really a game, but you get the point. Hit F5 and watch your little ball bounce away on your Windows PC.

And now for some XNA magic. The challenge was to create a Windows Phone game that does exactly that, not a Windows game. No problem! All you have to do is right click on “gravity” (the one with the Windows flag next to it) inside the Solution Explorer and choose “Create Copy of Project for Windows Phone”. Choose Windows Phone 7.1 and click OK. This creates the necessary files for a Windows Phone project but keeps the same source files which are shared between the Windows project and the Windows Phone project. Now right click on the Windows Phone Copy of gravity and select Set as Startup Project. Hit F5. This should launch the emulator and run your game. No code changes (you may need to rotate the emulator using the rotate button on the left to see this properly).

This is just a simple example, but you get the idea of how powerful this stuff is. You can improve the physics (or use the excellent Farseer library), you can include nice visual effects, a way of actually interacting with the game, menus, sprites etc. but if you can create a bouncing ball in 5 minutes you can see how easy this will be.

Here is the final solution if you are too lazy to type 12 lines (or you otherwise get stuck somewhere).

 

Why I code for Windows Phone

Posted by admin on March 01, 2012
Apps, Development, Games, Windows Phone, Windows Phone / 8 Comments

I am asked this question a lot the past few months. First of all it’s a good thing that people are curious about why someone would choose to code for Windows Phone instead of the other platforms, especially with the knowledge that iOS and Android have a huge market share combined and Windows Phone does not (yet). I have a few reasons, and although they might not satisfy some people, they are enough for me.

Reason 1:

Developing for Windows Phone is fun. I love the SDK, I love the tools, I love the whole experience. I have been developing games since I was a little boy and the reason back then continues to be the reason right now. I am having fun developing games. Back in the day (think: 8bit home computing), almost all of my creations were developed, tested and enjoyed by yours truly exclusively. There was no such thing as a “user base” but even so I was still enjoying developing games. I still do.  But in order for this to be fun, I have to have a fun experience doing it. C#, .NET, VS and XNA give me just that. An interesting example is given on the video below, which shows how the experience of creating a hello world app in the 3 platforms is.

Reason 2:

Making games is not my main activity. This blends a bit with the other reasons. Spending 1-2 hours per day developing games for Windows Phone allows me to go about doing the other things I am doing in my life (finishing my PhD and having a family). I strongly have the feeling that this would not exactly be possible using any of the other two platforms and be dedicated enough to master either of them. I am not saying it is impossible, but I truly feel efficient game developing on Windows Phone, even if I don’t have lots of time to spend. Also, because Windows Phone game development is not my main thing, income is welcome, but I am not going to starve because the market share is smaller than the other platforms. Yes, it is not enough to consider it my full time thing just yet, but exactly this brings us to :

Reason 3:

I have placed a bet with Windows Phone. And not just with Windows Phone, but with the up-and-coming Windows ecosystem. For me right now, Microsoft is the new Apple. It innovated constantly in many fronts and has some amazing successes to show for its efforts. For example, the xbox came late to the party, but managed to level the competition in just a few years. I knew since the beginning of the Windows Phone last year, that it was part of something much greater than just a phone OS. Microsoft’s strategy is to finally put the huge advantage of Windows to good use and win in the other fronts utilizing just that. Windows 8, Windows Phone 8 and the new Xbox platform next year will provide a unified ecosystem that will be unbeatable. My bet is to be involved in this as early as possible and this was last year when Windows Phone launched and I released my first game for the platform, Tetrada. I already have a few games and apps in the marketplace and the codebase and libraries I have developed are fully reusable not only in Windows Phone 8 “Apollo” (compatibility with Windows Phone 7 has been confirmed) but also in Windows 8 (MonsterUp on Windows tablets) AND XBox 360. This is a good investment for the future of the ecosystem on my part and since I can currently afford to not being sustained by the income from this activity, fun and investment for the future come first.

I think these are my main reasons. My current status may differ from yours of course but for me, I think that I am doing the right thing. The games I’ve made have proven quite successful and I am thoroughly enjoying that, so I can’t find a reason to stop doing what I’m doing. And I do believe I am going to win the Windows ecosystem bet. Nokia is in full time, Skype is here, big game and software studios are interested in the platform and it seems to be getting the thumbs up from a lot of tech-blogs, site and media in general.

The future of Windows Phone looks bright!

MonsterUp is a Best Game App and App of the Year finalist in Swiss App Awards 2012

Posted by admin on February 24, 2012
Development, Games, Windows Phone / No Comments

After an interesting and very busy time evaluating the nearly 130 submitted apps, it gives us great pleasure to announce the Swiss App Award 2012 nominees.

MonsterUp is in the 5 finalists for the Best Game App and App of the Year categories in Swiss App Awards 2012. What an honor!