Scale and retain aspect ratio

29 11 2008

After doing a bit of work on my level select menu, I came across the need to resize a texture to fit inside the a preview pane I’d created. However, not all of my preview images are going to be the same size or aspect ratio, nor do I want to enforce that restriction. I do, however, want to scale the images (up or down) to fit the pane without stretching them.

It’s a relatively simple procedure:

public static Vector2 FixAspectRatio(int imageX, int imageY, Vector2 paneDimensions)
        {
            float imageAspectRatio = (float) imageX / imageY;

            float paneImageAspectRatio = paneDimensions.X / paneDimensions.Y;

            if (imageAspectRatio > paneImageAspectRatio)
            {
                paneDimensions.Y = (paneDimensions.X / imageX) * imageY;
            }
            else
            {
                paneDimensions.X = (paneDimensions.Y / imageY) * imageX;
            }

            return paneDimensions;
        }

So given a restricted pane size (here “paneDimensions”) and the size of the image, you’ll get back a scaled size. The scaled size will have the same aspect ratio as the image dimensions. It will also be no bigger than the given paneDimensions in width or height.





Project Munny revealed

27 11 2008

Update: Project Munny is now referred to as Yet More Tower Defense. And there was much rejoicing!

Project Munny is the codename for the tower defense game I am currently working on. It’s codename was inspired by simply looking around my living room and spotting one of these critters. The game’s title hasn’t been finalized yet, so I’ll be referring to it as Project Munny for the time being.

Project Munny is a fairly traditional tower defense game with an emphasis on polish and playability. It’s primary purpose is for me to work my way through a complete game, something I’ve yet to actually do. I’ve made a fair amount of progress so far though and while the graphics are almost all placeholders, the game is actually quite playable. Notably, I’ve got working levels, towers, creeps, pathfinding, wave progression, upgrades/selling and a dozen other little things. Let’s take a look:

Project Munny Revealed!

Project Munny revealed!

You can see a lot of the debug drawing on there, which is actually easily toggled, but since this blog is about development, I thought it would be proper to leave it in there. Again, the sprites and hud are placeholders for the moment.

There are still a few big ticket items before I can really begin the balancing and polishing process though. For instance:

  • Gamepad input (currently keyboard/mouse for development)
  • Numerous effects (lighting, firing/hit effects)
  • Sound!
  • Virtually all of the best practices
  • High scores
  • Few more creep types, towers
  • Proper menus (functional but ugly placeholders at the moment)

And with that, back to work!





studioless games dev blog open!

27 11 2008

The blog for studioless games is now open! Somewhat fittingly, studioless games is also currently gameless but only in terms of releases. This blog will document the development of an XNA game I’ve been working on, from its current state (playable) through to eventual publication on Xbox Live Community Games.

More about studioless games, the project, and my part in all this are soon to come!