Public Group

# GetTickCount()

This topic is 4131 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, Sorry for the embarrassing questio coming up but I have a problem with jumping in a game. It's just a basic reconstruction of the old classic Chucky Egg. By using GetTickCount() I have managed to control the character's left and right smoothly, but, when I press the jump key it jumps far too fast. The test for the jump key is in the same place as the test for the left and right keys and they seem to be fine. Why is the jumping action acting like theres no delay at all?? Please can someone help and keep in mind that I'm very new to gaming in c++. styfir.

##### Share on other sites
You need to provide some more details. Most of us aren't psychic and hence fail to magically know how your code works.

##### Share on other sites
When you press Jump, there really exist delay. But they're still too short. Game will continually get keypress message.

You can add an int to lengthen this delay.

//game initint lendelay=0;//game main loop//key press check partif (keypressed(jump)&&(lendelay==0)){//do something herelendelay = 10; //maybe some larger number}//at the end of game loopif (lendelay>0) lendelay--;

##### Share on other sites
ok heres the code then

#include "Globals.h"

void Main_Loop()
{

HDC hdc;
hdc = GetDC(GameHandle);

if (KEYDOWN(VK_ESCAPE))
{
SendMessage(GameHandle, WM_CLOSE, 0,0);
}

chuckyendtime=(GetTickCount()-chuckystarttime);
if ((int)chuckyendtime>chuckyspeed)
{
if (KEYDOWN(VK_SPACE) && (lenDelay==0))
{
for(int i=1; i<60; i++)
{
Clear_Chucky();
py=py-gravity;
Draw_Chucky();

//gravity+=1;
}
gravity=1;
lenDelay=100;
}

while(GetPixel(hdc,px+3,py+35)==RGB(0,0,0))
{
Clear_Chucky();
py=py+gravity;
Draw_Chucky();

//gravity+=1;

}

if (KEYDOWN(VK_RIGHT))
{
if (px<757)
{
Clear_Chucky();
px+=3;

// when moving right check to see if theres a ladder //
{
contact=true;
}
if(contact)
{
}
Draw_Chucky();
}
}

if (KEYDOWN(VK_LEFT))
{
if (px>3)
{
Clear_Chucky();
px-=3;

// when moving left check to see if theres a ladder //
{
contact=true;
}
if(contact)
{
}
Draw_Chucky();
}
}

}
chuckystarttime=GetTickCount();
ReleaseDC(GameHandle,hdc);

}

See if you can find the problem I'd be really grateful Ta

##### Share on other sites
Quote:
 lendelay=100;

maybe it's just too large. the number here, take 100 as example, means you multiply delay by 100.

##### Share on other sites
Ive tried smaller numbers like 50 and 25 but still, no effect on the speed - I just dont know...

thanks anyway,

styfir.

BTW how do you post code and have it all nice and indented?

##### Share on other sites
[ source ] [ /source ] tags.

##### Share on other sites
use [souce] and [/source] tag

##### Share on other sites
Thank you

any more thoughts on the problem at hand??

styfir.

##### Share on other sites
granted I might have missed something, but lenDelay doesn't do anything as far as I can see in the code you posted. It's tested for zero in an if, and if it is, it's set to 100. Also, you have a for loop that does nothing but run through the code in the loop 60 times, as fast as it can. No timing is involved in the loop, so that's why it looks like GetTickCount has no effect on it, 'cause it doesn't. Again, I might have missed something, but that's what I can gather.

If you've modified the code at all (and even if you haven't) post it up properly so that the indentation/formatting is seen, it's a lot easier to see an error that way, for us and for you.

• 17
• 10
• 19
• 14
• 19