This is a simple tutorial on how to build a simple animation using the new "Dark GDK" for Visual C++ 2008 express
Required Programs:
1.
Visual Studio C++ 2008 Express2.
The "Dark GDK" add-on for VC++ 08=============================================
After downloading and installing the dark GDK, open VC++ 08 and click "File->New->Project" (or "ctrl+shift+N").
Under project types, click "Wizards".
Select "Dark GDK - 2D Game", name the project something like 'Dark GDK - 2D Game1", select the folder in which you want your project to be stored in, and click "OK".
Now, under solution explorer, click "main.cpp".
There will already be a neat little bit of code there and if you run it (ctrl+F5) a neat animation will be displayed!
Now for the editing:
1. Let's edit the code that places the object at a random location, find this code
CODE
for ( int i = 2; i < 30; i++ )
{
// create an animated sprite and give it the ID number from the
// variable i, next is the filename, now we come to how many frames
// across and down, in our case this is 4, finally we come to the image
// ID that the sprite will use, again we use i
dbCreateAnimatedSprite ( i, "sprite.bmp", 4, 4, i );
// position our sprite at a random location
dbSprite ( i, dbRnd ( 640 ), -dbRnd ( 1500 ), i );
}
and change it to:
CODE
int i = 2;
dbCreateAnimatedSprite ( i, "sprite.bmp", 4, 4, i );
// position our sprite
dbSprite ( i, 100 , 100, i );
The code will now display 1 object and it will fall to the bottom of the screen.
2. Now, we will make the object work off of user input.
-Find this code:
CODE
// now we come to our main loop, we call LoopGDK so some internal
// work can be carried out by the GDK
while ( LoopGDK ( ) )
{
// run a loop through all our sprites
for ( int i = 2; i < 30; i++ )
{
// move the sprite down and play its animation
// moving from frame 1 to 16 with a delay of 60 ms
dbMoveSprite ( i, -2 );
dbPlaySprite ( i, 1, 16, 60 );
// check the position of the sprite, if it has gone off scren
// then reposition it back to the top
if ( dbSpriteY ( i ) > 500 )
dbSprite ( i, dbRnd ( 640 ), -dbRnd ( 1500 ), i );
}
// here we check if the escape key has been pressed, when it has
// we will break out of the loop
if ( dbEscapeKey ( ) )
break;
// here we make a call to update the contents of the screen
dbSync ( );
}
and replace it with this code to make it work off of user input:
CODE
//NOW: let's make our sprite move on user input!//
int SDS = 1;
while ( LoopGDK () )
{
if(dbControlKey()) //Toggle constant animation on\off//
{
if(SDS == 1)
{
SDS = 2;//animation is off
}
else
{
SDS = 1;//animation is on
}
}
if(SDS == 1)//check to see if animation is toggled
{
dbPlaySprite ( i, 1, 16, 60 );
}
if(dbDownKey())//do something on user input
{
dbMoveSprite ( i, -2 );
dbPlaySprite ( i, 1, 16, 60 );
}
if(dbUpKey())//do something different on different user input
{
dbMoveSprite ( i, 2 );
dbPlaySprite ( i, 1, 16, 60 );
}
// here we check if the escape key has been pressed, when it has
// we will break out of the loop
if ( dbEscapeKey ( ) )
break;
// here we make a call to update the contents of the screen
dbSync ( );
}
3. Test the application:
press [Ctrl]+[F5] to run the program.
Now, the program should display something like this:
bitmap.bmp ( 991.74k )
Number of downloads: 650=============================================
Congrats! You can now control what the object does!
Pressing the up and down arrows will move it on the screen and pressing [Ctrl] will toggle the animation!
Other controls can be added, such as useing
dbLeftKey &
dbRightKey.
=============================================
I hope this tutorial is helpful, it's the first one I have done. There are probably some errors in it, let me know if there are.
---------------------------------------------------------------------------------
-aj32
This post has been edited by aj32: 9 Feb, 2008 - 09:42 AM