Showing posts with label xna. Show all posts
Showing posts with label xna. Show all posts

Thursday, November 1, 2007

Comparing XNA and Silverlight for 2D game development

[This was originally posted at http://timstall.dotnetdevelopersjournal.com/comparing_xna_and_silverlight_for_2d_game_development.htm]

Most developers are interested in writing games, if even just as hobbyists. That's why there's all this buzz around about two (relatively) new technologies - XNA and Silverlight. I wrote a simple real-time strategy on each platform, and I found the differences very educational. There's a lot of overlap. For example, the powerful Farseer Physics Engine is being marketed to both groups. The best blog I've seen so far on this has been MVP Bill Reiss's stuff - he's written good tutorials for game development on both platforms.

 

 XNASilverlight 1.1
SummaryA platform designed explicitly for gamer development. XNA is obviously more powerful, as it's a client download, requires DirectX, and is optimized specifically for games and high-speed (including 3D) rendering.A new plug-in that hosts xaml, letting you write thick-client applications in the browser. Silverlight lets you write many things, of which games are just one.
Why care?Solves rendering and gameLooping such that anyone can now make a simple game.Allows you to write simple games over the web, so you can share with anyone.
Age of technology?Came out about a year agoStill in alpha
RenderingThe Game class has a built-in gameLoop, which fires both an Update and Draw. The Update method updates your models, positions, and logic, whole the Draw method then uses those models to draw images to the screen via the SpriteBatch. If you want to add a new object, simply display its sprite. If you want to remove that object, stop rendering its sprite.

For 2D games, XNA just displays sprites - it's not vector based (as far as I could tell).

You add objects using Xaml, and then the objects stay rendered until you explicitly remove them from the root canvas.

Xaml is vector based, so you can draw shapes as well as sprites.

 

AnimationDeveloper manually handles by updating the position and what images to show in the code.You can use Xaml storyboards for simple animation sequences. You can also set the position, rotate, and clip of a sprite.

SEE: how to make an animating sprite

Transparent ImagesHandled by setting all pixels to magentaHandled by making a transparent png image.
Killer Features
  • Awesome performance
  • 3D games
  • Deploys over the web, on all major browsers, using just FTP (you don't even need ASP.Net on the server)
  • Integrates with Html and Ajax, so you can also use web controls (for example, TruckWars uses an html dropdown to let you select levels, and an html button to both reset levels, and provide a confirm box)
Big Problem

 

Slow performance compared to XNA, but good enough for classic 2D games.
Benefit to learningGood way for a hobbyist to get started.I personally think that the skills needed to make Silverlight games are much more marketable because they can also be applied to enterprise and business development. For example, if you can make Pacman in Silverlight, you can make graphs and input controls that the business world cares about. While XNA can make graphs too, there's a much bigger market for web development than on the XNA platform.
TutorialBill Reiss on XNABill Reiss on Silverlight
TruckWars sampleTruckWars in XNA (you need to download a bunch of stuff)TruckWars in Silverlight (runs right in the browser)

 

Silverlight and XNA are both easy to get started, especially with the active communities evolving around each of them. Even if you're a full-time .Net developer, it's still fun to toy around with these technologies on the side.

 

Personally, I started with XNA, but quickly moved to Silverlight. For me, the deciding factor is that (1) The Silverlight skill set is more applicable to my job (enterprise development), (2) Silverlight is so much easier to deploy, so I can share the results with others.

 

Tuesday, October 16, 2007

XNA Real-Time-Strategy Game (with source code)

[This was originally posted at http://timstall.dotnetdevelopersjournal.com/xna_realtimestrategy_game_with_source_code.htm]

I mentioned in my last post about XNA that I've created a sample game, complete with full source code.

 

 

You control the green tank by using the mouse. Left moves, right fires. The goal is to push the numbered crates onto the pink "Victory" tiles, and then hit the green semi-circle button. This demonstrates several things:

  • Collisions - this uses a simply polygon collision detection. It also handles heights - a fireball hovers, so it can pass over the water, but the tanks cannot.

  • User input - collecting mouse input (position, left, right buttons)

  • Animation - the water animates

  • Multiple creatures of different sizes. The green bushes (the square things) increase in size as your tank gets closer.

  • Interacting objects - you can push crates, fire at other units, hit the push button, and collect a powerup to increase your firing rate.

  • Messages

  • Opacity

  • A dashboard section on the button for user information

  • The ability to pause the game - which freezes everything (including the game clock).

Note that all the graphics were made with MSPaint.

 

The code is pretty sloppy, as it was just a toy project and my main point was to explore XNA. There's a ton that could be improved about it.

 

Obviously it's just a cute sample. Especially as XNA can handle scrolling, 3D games, and a lot more, this only skims the surface.

 

One point of note is unit-testing. There is a lot of complex code (movement algorithms, models, collisions, interactions, etc...) that should ideally be tested. However Visual C# express doesn't support unit-testing. So, I made the core DLL be referenced in another solution, which can then test it.

 

Next up: re-writing this in Silverlight. I'll go into more of the details there.

Monday, October 15, 2007

XNA Game Development

[This was originally posted at http://timstall.dotnetdevelopersjournal.com/xna_game_development.htm]

XNA is a Microsoft platform for easily creating games. These can run on Windows, and even the XBox.

 

Essentially, XNA handles the difficult part of image rendering, and provides the developer a simple API. Bill Reiss provides some excellent tutorials to get you started.

 

An XNA project has the Game class, which provides three main methods;

  1. Initialize - sets everything up

  2. Update - updates the models based on a game clock

  3. Draw - renders images to the screen based on the game clock, and what you updated.

This is a very intuitive API which makes it easy to make simple games, especially 2D classics.

 

What I find interesting about XNA is that many developers got their start by trying to program simple computer games. However, back in the 80s or 90s, the bar was high because it's relatively difficult to do the image rendering, especially something fast enough for a real game. Many more developers can do the algorithms and simple logic than can do the rendering. Even with Windows GDI+, it just wasn't fast enough. But XNA actually works fast enough to make it worth while.

 

XNA games can also bedeployed to other Windows machines, you "just" need to install: (1) .net 2.0 redistributable, (2) XNA redistributable, (3) Direct X. It's motivating to be able to share your work with others.

 

In the next upcoming posts, I'll provide an XNA sample game I created, and compare it to Silverlight.