Page 1 of 1

Dark GDK: Getting Started

#1 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Posted 16 June 2010 - 10:01 AM

Dark GDK: Getting Started


Introduction
I've noticed that the resources for the Dark GDK are pretty limited. So, I've decided to start a series of tutorials that explain how to accomplish some of the more common tasks in the Dark GDK. In this tutorial, I will discuss how to create and run a new project. I will also show how to load 2D images.

Downloading and Installing the Dark GDK
If you have not done so already, you can follow the instructions on this page to download and install the Dark GDK and the necessary resources.

Creating A New Project
Open Visual Studio or Visual C++ Express and select: File>New Project>Wizards>Dark GDK-Game. Enter a name (such as DarkGDK_GettingStarted). Press OK.

That's it. You've created a new Dark GDK project. Go ahead an build (F6) and run (F5) your application. You should see a small window with a black screen.

The Code
Double-click on the Main.cpp file from the SolutionExplorer. Let's briefly discuss the code that you see.

// Dark GDK - The Game Creators - www.thegamecreators.com

// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application

// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"

// the main entry point for the application is this function
void DarkGDK ( void )
{
    // turn on sync rate and set maximum rate to 60 fps
     dbSyncOn   ( );
     dbSyncRate ( 60 );

     // our main loop
     while ( LoopGDK ( ) )
     {
          // update the screen
          dbSync ( );
     }

     // return back to windows
     return;
}



The DarkGDK method is the game's entry point, and main body.

The dbSyncOn command allows the application to update the screen. dbSynRate sets the rate (in frames-per-second) at which the screen should update.

This is the game loop. This loop run 60 frames-per-second (or whatever the frame rate is set to) until the loop is "broken" (for example pressing escape while the game is running will break out of the loop and cause the game to exit). This is where you will put you game logic (movement, collision detection, artificial intelligence, etc...).

dbSync tells the screen to update. This will draw any content to the screen. Although this method can be called at any time during the game, you should not call it more than once inside the game loop.

Loading 2D Images
Dark GDK makes loading game content really simple. All you need to do is call the appropriate method, and insert the path to the file, along with an ID. The ID must be unique, and can be used later to access the loaded content.

In order to load an image, you must call the dbLoadImage. The image loaded must be one of the following type: BMP, JPG, TGA, DDS, DIB or PNG. An image of type TGA, DDS, or PNG can contain alpha channel data, meaning it can be transparent.

Once the image is loaded, you must draw it to the screen. If you would like to simply draw the image to the screen at a certain location, without modifying it, you can just use the command dbPasteImage. If you would like to scale, rotate, flip, mirror, stretch, or animate the image, you must create a sprite. A sprite can be created using the command dbSprite.

In the following code, I load an image, create a sprite, and make the sprite fill the screen:

// Load an image and assign it the ID "1".
dbLoadImage("Media/Textures/Sprite.png", 1);

// Create a sprite from the loaded image. 
// The sprite is assigned the ID "1", 
// and positioned in the top-left corner of the screen.
dbSprite(1, 0, 0, 1);

// Scale the sprite to fill the screen.
dbSizeSprite(dbScreenWidth(), dbScreenHeight());



This code is placed in the DarkGDK method, before the game loop. The image is loaded and given the ID "1". A sprite is then created, given the ID "1", and positioned at the top-left corner of the screen (0,0). Two objects can have the same ID if they are different type. An image and a sprite can have to same ID, but two images cannot.

Conclusion
I'll end this tutorial here. Soon I'll try and post a few more tutorials that discuss more complex topics. Until then, play around with some of the commands, entering different values. Look over the documentation and familiarize yourself with the many commands.

Is This A Good Question/Topic? 2
  • +

Replies To: Dark GDK: Getting Started

#2 taylorc8  Icon User is offline

  • B&

Reputation: 149
  • View blog
  • Posts: 1,572
  • Joined: 21-July 09

Posted 27 June 2010 - 07:42 AM

May want to familiarize with moving the camera also, it would be nice of you to add that to this tutorial. It seems like one of the most basic things todo.
Was This Post Helpful? 0
  • +
  • -

#3 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Posted 29 June 2010 - 04:41 PM

Thanks for the suggestion. I'm planning on making a few more tutorials for Dark GDK when I get the time, and I'll definitely go over that.

This post has been edited by lesPaul456: 29 June 2010 - 04:42 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1