Friday, September 09, 2005

Creating the 2D Graphics: The unstoppable blackhole of time

Well, I've been learning some about animating 2D characters. I understand now why people hire artists to do the work for them. One, it's very time consuming and two, you begin to realize you're not very good and to take the time to become good takes away the time from development so number two is basically the same as number one, it's time consuming.

I'm hoping to get some screenshots up soon of some of my in game graphics. I'm also hoping that I'm doing the animations right. So far, how I'm accomplishing animation is just loading up a different texture (or a new section of a texture) that has the same graphic with some slight changes.

This becomes kind of like flipping through once of those stick pencil flipbooks. So when you start walking a character you start cycling through the textures to simulate his movement while walking.

When the player stops walking, you revert back to your standing still texture.

Anyway, hoping to get some screenshots up soon as well as get some more code posted.

It's just unbelievable the number of images needed for each type of movement. Even for creating dropped items like coins. If you want them to have some type of glimmer or such, yep, need a couple of images for each item. Like I said, time consuming.

Wednesday, September 07, 2005

Background Class

Well, I didn't finish my background class like I thought I would this weekend. A recent purchase kind of got in the way (Guild Wars is awesome!)

But I have thought about somethings that it needs to be able to do so I thought I would jot some of those thoughts down here.

1. Autoscroll flag - basically sometimes you want the background to autoscroll and sometimes you don't.

2. Wrap textures flag - sometimes you want to keep cycling through your background textures and sometimes you don't.

3. Multiple background textures - break the level up into smaller graphics

4. Horizontal Scroll/Vertical scroll - able to scroll backgrounds horizontally or vertically depending on game and level.

So currnetly I have the ability to autoscroll a single background image horizontally continuously. Still a ways to go to provide all the other functionality.

Still pretty cool that it's working though. I had some fun with it thise weekend by having my son draw a background on paper and then draw some characters on another paper. We scanned those in, I added them to the game and viola his litte guy he drew was now walking all around the background he drew. He thought that was pretty cool!

Maybe I'll post up some pictures of that later.

Saturday, September 03, 2005

Scrolling a 2D Background: Trouble a brewing!

Well, after doing the post yesterday with a small little code sample of how I was scrolling my 2D background, I stumbled across a LITTLE problem.

I began working on my project on another computer and lo and behold the Managed DirectX function Draw2D was not recognized.

So I'm going to have to do some research into which computer has the newest DirectX 9 dlls and figure out wether Draw2D will be in the final relase or will not be in the final release. Until then, I have fixed my code using the standard Draw function which is seems to work fine in both versions.

I'll update my final findings on this matter once it has been cleared up for me.

Drawing the 2D background using the standard Draw function.

'Scroll and draw the Background
Public Sub Draw()
    mBackgroundSprite.Begin(SpriteFlags.AlphaBlend)
    mBackgroundTextureSize = New Rectangle(mXPosition, _
      0, mWidth, mHeight)

    mBackgroundSprite.Draw(mBackgroundSpriteTexture, _
      mBackgroundTextureSize(0), New Vector3(0, 0, 0), _
      New Vector3(0, 0, 0), TransparentColor)

    mBackgroundSprite.End()
    mXPosition += 1
End Sub


Basically using the Draw function is very similar to using the Draw2D function, you'rejust passingin vectors now instead of a point.

Friday, September 02, 2005

Scrolling a 2D Background

The first hurdle I encountered when working on a 2D game with Managed DirectX WITHOUT using DirectDraw was trying to figure out just how in the world to scroll a 2D background.

Luckily I was pointed towards the MSDN DirectX forums and asked just that question and was immediately provided with a solution. After examining the code example provided, I was able to adapt it for my own needs and get my 2D background scrolling.

Basically the important parts of my code to create an auto-scrolling 2D background in Managed DirectX are shown below in a Draw sub of a Background class I created.


Public Sub Draw()
    mBackgroundSprite.Begin(SpriteFlags.AlphaBlend)
    'Change the X position of the texture size. This will keep
    'changing the portion of the texture that is drawn to the screen
    mBackgroundTextureSize = New Rectangle(mXPosition, 0, mWidth, mHeight)
    mBackgroundSprite.Draw2D(mBackgroundSpriteTexture, _
      mBackgroundTextureSize, mBackgroundTextureSize, _
      New Point(0, 0), TransparentColor.ToArgb)
    mBackgroundSprite.End

    mXPosition += 1
End Sub



The following class level objects were used in the above sub:


Private mBackgroundSpriteTexture As Texture
Private mBackgroundTextureSize As Rectangle
Private mBackgroundSprite As Microsoft.DirectX.Direct3D.Sprite
Private mWidth As Integer
Private mHeight As Integer
Private mXPosition As Integer


Now the above code is far from complete in getting a successful auto-scrolling background and my code does quite a bit more than what I have provided here (continual autoscroll of the background, ability to scroll in X direction or Y direction, etc). I'm just not ready to show that code just yet (still enhancing it) but I did want to give anyone else out there trying to figure out how to scroll a 2D background some more code samples to pick from on the web.

I'll post more on my Background class after more enhancements take place.

Thursday, September 01, 2005

Managed DirectX: A new beginning

Well, it's been a long time since I last posted. (Not that anyone was really coming here including myself)

But I've decided this is the ideal place to begin journaling my current project. I am currently working on building a 2D game using Managed DirectX and VB.NET. My goal was to learn to use Managed DirectX while learning how to drop the now deprecated DirectDraw.

My previous experience with DirectX has been slight. I've written a Tetris clone which I almost completed (it didn't change level and had no splash screen or menu, but it was playable, kept score, had music and sound effects and even flashed when you got a Tetris), which was done using VB and DirectX 8. But that game used only DirectDraw.

I did a few more using VB and DirectDraw as well, I had a starfighter game I made for my son. It kept score, a scrolling background and multiple enemies and shots on the screen at one time, collision detection and music. I purposefully made that game so the star fighter couldn't die (the ultimate hero!) so that I didn't have to keep restarting it for my son an he could play for eternity. (He still enjoys playing it).

I've also done some simpler games using the BitBlt API and I have a swath of those in various stages of completion.

But this! This is my first project that I'm going to take all the way. End goal is to have a fully compiled game with all the works. I haven't decided on everything I want it to do yet (I'm obviously going to keep it simple since I"m just starting out with Managed DirectX), but as I learn more of what I can do with DirectX (again WITHOUT using DirectDraw), the shape and form of my 2D Managed DirectX game will being to take shape.

My plan is to not so much publish how my game looks and how it plays but more to chronicle the DirectX hurdles I come across and what I did to solve them. I'm hoping to accomplish a few things with that.

1. To repay the favor to the many other DirectX coders that have helped me out in numerous ways by posting their code samples and answering my questions. Especially one I met in the MSDN Forums who helped kick start this project with an answer to my question

2. To take the sound advice of someone I met at the Portland Code camp who said if you are starting a project, make sure you journal it. You'll thank me later for doing that. Just make sure you record what you're doing.

3. To learn how to work with Managed DirectX to program a 2D game WITHOUT DirectDraw. DirectDraw has been deprecated (i.e. meaning it's no going to be supported much longer) so I want to learn how to develop games without it. Unfortunately there's not a lot of code examples out there for the 2D coder that don't use DirectDraw so I'm kind of blazing some new ground here for the 2D game developer.

3. To provide a log for what I hope is going to be a fun and interesting project.


So this is it. The grand project kick off. Let's see how it goes.