How to make sprites move smoothly??
pressing the direction keys to make sprites move, but i found that the bltfast makes flashing on the screen using win32 api(WM_KEYDOWN)
e.g.
# define STEP whatever
case VK_LEFT:
Sprites.xPos -= STEP;
it will cause the flashing effect, but how to make it smoothly??please...
How to realize your every dreams u ever made?? ---- Just Do It!! (haha, NIKE should pay me for adv, haha...)
November 09, 2000 11:38 PM
I don''t know if it would help, but you could try to use a getasynckey instead of rellying on the wParam.
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
I hope you using some kind of backbuffer !!, if not start by using one.
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
I hope you using some kind of backbuffer !!, if not start by using one.
I had this problem recently - the easiest solution is to use a backbuffer.
(It''s a problem with the display, not with the method you are using to get the keypresses, i believe).
(It''s a problem with the display, not with the method you are using to get the keypresses, i believe).
a backbuffer???
i load the bitmap into an offscreen surface, and blit it into the backbuffer, then make the primary surface flip. and the flashing remains.
such as:
UpdateFrame() {
g_lpDDSBackBuffer->BltFast(0, 0, g_lpDDSOff, &rcRect, DDBLTFAST_SRCCOLORKEY);
g_lpDDSPrimary->Flip(NULL, 0);
}
in WinMain()
{...
...
while (TRUE)
{
MsgLoop();
UpdateFrame();
}
i load the bitmap into an offscreen surface, and blit it into the backbuffer, then make the primary surface flip. and the flashing remains.
such as:
UpdateFrame() {
g_lpDDSBackBuffer->BltFast(0, 0, g_lpDDSOff, &rcRect, DDBLTFAST_SRCCOLORKEY);
g_lpDDSPrimary->Flip(NULL, 0);
}
in WinMain()
{...
...
while (TRUE)
{
MsgLoop();
UpdateFrame();
}
How to realize your every dreams u ever made?? ---- Just Do It!! (haha, NIKE should pay me for adv, haha...)
I have that kind of problem too, only it is not a "flashing" thing...the motion just jerks every once in awhile for a split second..weird..if there''s something wrong the "jerks" should be frequent or periodically..in this case it''s just random and just every once in awhile.
Check out what I mean: http://www.stas.net/1/dreamd/
Go to "Free Stuff" and download the space.zip
Check out what I mean: http://www.stas.net/1/dreamd/
Go to "Free Stuff" and download the space.zip
I made some easy 2D animations in OpenGL.
Didn''t get any flickering-problem.. I believe the solution was that I used a back buffer and that OpenGL times the buffer switch with the vertical sync. of the monitor. (am I right, or don''t I know what I''m talking about?)
-try the thing Anonymous Poster posted.
Didn''t get any flickering-problem.. I believe the solution was that I used a back buffer and that OpenGL times the buffer switch with the vertical sync. of the monitor. (am I right, or don''t I know what I''m talking about?)
-try the thing Anonymous Poster posted.
how many backbuffers do you have? i tried using 1 backbuffer and i experienced the same thing. i increased to 3 and the flashing stopped. maybe you need to increase your backbuffercount.
pcvsee, what do you mean?
I thought backbuffer was the same thing as setting OpenGL to use double buffering. So that you render one scene in memory and then swap it with the scene (buffer) currently shown on the screen. And here I think the problem is. That you swap the buffers without timeing it with the vertical sync. of the monitor.
I can''t see how using three buffers solves this... Since switching between three buffers wouldn''t make any sense.. Rendering in one buffer, one buffer on screen and one buffer (the third one) just sitting there..
Can''t someone in the "know-how" make an intelligent respons to this?? =)
I thought backbuffer was the same thing as setting OpenGL to use double buffering. So that you render one scene in memory and then swap it with the scene (buffer) currently shown on the screen. And here I think the problem is. That you swap the buffers without timeing it with the vertical sync. of the monitor.
I can''t see how using three buffers solves this... Since switching between three buffers wouldn''t make any sense.. Rendering in one buffer, one buffer on screen and one buffer (the third one) just sitting there..
Can''t someone in the "know-how" make an intelligent respons to this?? =)
You can handle WM_KEYDOWN and WM_KEYUP
OnKeyDown()
{
switch(nChar)
{
case VK_....:IsLeft=true;break;
}
}
OnKeyUp()
{
switch(nChar)
{
case VK_....:IsLeft=false;break;
}
}
It works fine in my game no flicering at all. (DirectX)
OnKeyDown()
{
switch(nChar)
{
case VK_....:IsLeft=true;break;
}
}
OnKeyUp()
{
switch(nChar)
{
case VK_....:IsLeft=false;break;
}
}
It works fine in my game no flicering at all. (DirectX)
I had the same issue, but it was extremely random. I tend to agree with the few that say it is due to the Monitor Refresh Rate. There is a function you can call, called WaitForSync(). This function will force DirectDraw to wait and refresh with your monitor''s sync rate. This should reduce the amount of flashes, if not remove them all. For more information on that function, check out the SDK or msdn.microsoft.com
Kevin =)
Kevin =)
-----------------------------kevin@mayday-anime.comhttp://www.mayday-anime.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement