More Nebulas

A while back (was it really over a year ago) I started collecting some real nebula photos to start adding some more variety to my backgrounds.  The technique I use is to take a real nebula photo and process the photo, sometimes completely by hand, to extract all the clutter/stars so that I can later re-composite them back into my scenes.  I’ve got a technique that works pretty well now for many images.  Specifically, so I don’t have to hand edit as much with the clone tool.  I do all my bitmap work in GIMP, which is a wonderful open source graphics package.

Solaroids 2013-02-16 12-46-05-36

Solaroids 2013-02-16 13-08-46-55

Solaroids 2013-02-16 13-09-11-55

Solaroids 2013-02-16 13-09-56-56

OK, so the last one isn’t a nebula, but same technique.


Posted in General | Comments Off on More Nebulas

XNA Quick Tip – XNA SpriteBatch and Garbage

The XNA SpriteBatch class maintains an internal array to hold sprites to be drawn between calls to Begin() and End() if a sort mode is used. This array will grow as necessary, however, the reallocation will inevitably result in extra garbage that will eventually need to be collected.  On the XBox 360 this is quite expensive and so in general it is recommended to limit garbage wherever possible.

If you know the upper bound on the number of sprites to be drawn in a single batch, you can force the draw before the game begins.  This is pretty easy to do, however to make it even easier when you have multiple SpriteBatch instances for different purposes I use the following simple wrapper class in Solaroids that has a new constructor that takes an extra argument for the expected number of active sprites:

/// <summary>
/// Wrapper around a SpriteBatch that pre-allocates internal sorting buffers by drawing a set of sprites thus forcing the buffers to be expanded.
/// </summary>
public class PreallocatingSpriteBatch : SpriteBatch
{
  /// <summary>
  /// Initializes a new instance of the <see cref="PreallocatingSpriteBatch"/> class.
  /// </summary>
  /// <param name="graphicsDevice">The graphics device.</param>
  /// <param name="expectedActiveSprites">The expected number of active sprites.</param>
  public PreallocatingSpriteBatch(GraphicsDevice graphicsDevice, int expectedActiveSprites)
    : base(graphicsDevice)
  {
    ForceBufferAllocation(expectedActiveSprites);
  }

  /// <summary>
  /// Forces the buffer allocation.
  /// </summary>
  /// <param name="expectedActiveSprites">The expected number of active sprites.</param>
  private void ForceBufferAllocation(int expectedActiveSprites)
  {
    Texture2D tex = new Texture2D(GraphicsDevice, 16, 16);

    Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);

    for (int i = 0; i < expectedActiveSprites; i++)
    {
      Draw(tex, Vector2.Zero, Color.White);
    }

    End();
  }
}

Solaroids Teaser 1

It’s getting to the point where I had probably start making some teaser trailers…  So here is the first one made in the simple, but seems to work pretty well, Windows Live Movie Maker.  The music was made on my 4th Gen iTouch using Music Studio. What a sweet little App.  It’s like having Sonar X1 at your fingertips — well not quite, but still pretty cool, and did I say portable!


Audio positioning and a new boss

Wow it’s been awhile.  I haven’t had any free time to work on Solaroids since last June.  With a big work commitment out of the way and a much needed holiday break, I had a chance to work on it for a few days.  The results are a new boss ship, some newly done sound effects, and positional audio complete with Doppler effects on the missiles.  XNA sure makes it easy to put this stuff together, and after this update I’m a lot more confident with the XACT audio software.

Here’s a couple of screen shots and a video showing off the new features.

Solaroids 2010-01-07 22-54-35-33

Mean enough?

Coming in for the kill

Coming in for the kill

Surprise!

Surprise!


A few small updates

With spring here, development has slowed down quite a bit.  There are just to many yard projects that have to get done!

Recently, I did manage to spend a little time adding a few new features.  I adapted the XNA lens flare sample designed for 3D games to add the effect to my sun.  It worked out pretty nicely (and cheap to implement).  I swapped out the occlusion queries with a simple 2d  query to calculate the percentage of the sun that is on screen which then controls the visibility and intensity of the effect.  This technique doesn’t allow sprites to block the flare effect though, but it sufficient for what I wanted to achieve.

New lens flare effect

New lens flare effect

I while back while I was re-drawing my stand in graphics in Inkscape, I drew some pieces to build up a snake like enemy.  Combining that with some prototype serpent code I wrote quite a while ago (I can’t believe it was still functioning with all my engine changes) results in the following.

New serpent enemy

New serpent enemy

Right now each segment can take a hit, and that hit results in a cascading set of mini explosions down to the tail, which then explodes leaving the serpent a little shorter.  I plan on changing things around to show the energy being directed down to the tail – maybe the typical arcade shooter flashing sprite effect. Another thought is to have the serpent break into multiple pieces that then form a head and continue to pursue.

Here’s a video showing the two new features.  If you watch closely as the serpent ship comes on the screen you can actually see the segments being added which is a current bug.  The ship builds itself over time after it has been added to the scene.  As I use a queuing mechanism to record the orientation of the segments in the kinematics chain based on time delays.  Final code will build the entire chain at construction time.


Inkscape for Games

I’ve been using Inkscape, a freely available open source 2d vector drawing package, to do my 2d art for Solaroids and it has been working out quite nicely.  The limitations of vector art have given Solaroids a distinctively smooth style that I kind of like for a game such as this.  It has a certain modernized retro-feel to it that fits perfectly considering its graphics originated many many moons ago in a different computer era.

playershiplarge2

Redux

playershiplarge

Original

Here’s a comparison of the original player ship done in Deluxe Paint III on the Commodore Amiga vs. the new version done in Inkscape. Of course the original is being linearly interpolated by the web browser, and actually looked pretty good at it’s designed for resolution of a whopping 320x200x5bit, but the Inkscape version looks crisp and beautiful. Due to the nature of Inkscape and svg, the new version is actually resolution independent, so I can export it at whatever resolution is required.  Solaroids supports 1080p and so my graphics are exported large enough to support full detail at 1920×1080.

A couple of tips when using Inkscape for game development.  I export my images as png files, and unless you go into the Document Preferences and set the background color to something suitable (black instead of white in my case) you’ll get sub-pixel halos around your images when positioning, scaling, and rotating them in XNA.  This appears to be due to the graphics hardware using the neighboring (fully transparent) pixel color during interpolation.  It may also have something to do with the sprite sheet content processor I’m using as well.

Another cool thing about Inkscape is it remembers the export filename based on the set of shapes selected, so if you have multiple sprites in your document, you can repeatedly re-select various ones and it will remember your last filename for the selection as well as other export settings such as dpi etc.  Very nice.


New video of gameplay showing new effects

I posted a new video at youtube to show some of the new additions in action.  New sun and planets.  New middle ground stars to give it a little more dimension.  I fixed the background stars as it had a funny artifact that was visible at certain gamma levels.  I also changed the explosion particle system to have a red/orange tint to give it a little more color and increased the size of icons in the player HUD and made them resolution independent.  This one also has a different more mellow audio track I composed, great for cruising around in space and clearing space debris.

There is also a SD version available if your computer can’t handle the HD version.


Another video test

Here’s another video test showcasing one of hopefully many enemy ships – a spinning, turret wielding, and missile launching menace.


Posted in General | Comments Off on Another video test