Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Walk Cycle Problems

Author
Message
lucky_shot
12
Years of Service
User Offline
Joined: 7th Jan 2012
Location:
Posted: 8th Jan 2012 05:37
I'm working on my first dark basic project but I know the basics of c++. It's pretty much a simple game, really its jsut a guy walking around a screen, I have further plans for it but i'm stuck with this one thing. When I press the s key the character walks down and the walk cycle animation flips through but when I press w the character goes up like programmed it to but the animation locks like he is paralyzed.

Thanks, I'm a mere beginner with c++ and darkgdk so sorry if I did something stupid.

#include "DarkGDK.h"


void DarkGDK ( void )
{

dbSyncOn ( );
dbSyncRate ( 60 );
dbSetDisplayMode(560, 240, 32);//Screen Resolution I dont recommend changing this as you'll just get alot of blackspace.
dbDisableEscapeKey ( );

dbSetImageColorKey ( 255, 0, 255 );//makes the pink on sprites be alpha

dbLoadImage ( "map.bmp", 1 );//Loads Background (grass texture)
dbSprite ( 1, 0, 0, 1 );


dbCreateAnimatedSprite(2,"character.bmp",2,1,2);//Loads walk cycle as well as the character.
dbSprite(2,100,50,2);



while ( LoopGDK ( ) )
{
if (dbKeyState(17))
{
dbPlaySprite(2,1,2,100);
dbMoveSprite(2,1);
}

if (dbKeyState(31))
{
dbPlaySprite(2,1,2,100);
dbMoveSprite(2,-1);
}

else
{
dbSetSpriteFrame(2,1);
}


if(dbEscapeKey() == 1)
{

break;
}
dbSync();


}


for ( int i = 1; i < 30; i++ )
dbDeleteSprite ( 2 );


dbDeleteImage ( 1 );


return;
}
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 8th Jan 2012 15:13
else
{
dbSetSpriteFrame(2,1);
}

This superseed the "up" animation. Adjust your code. I would put something like:
if ((!dbKeyState(31))&&(!dbKeyState(17)) dbSetSpriteFrame(2,1);

You will have to make this work for every key that causes animation to occur.

The fastest code is the code never written.
lucky_shot
12
Years of Service
User Offline
Joined: 7th Jan 2012
Location:
Posted: 8th Jan 2012 16:57
Alright I finally fixed it by just deleting the else statement all together. It works great now.

Thanks for the help.

Login to post a reply

Server time is: 2024-04-26 20:30:12
Your offset time is: 2024-04-26 20:30:12