First steps in animation.. Kinda
-
I created a little app where you throw a ball and it bounces. You can see the app here: http://thresholdx.com/misc/Ball.exe To throw the ball, hold the left mouse button, gain some speed and release. I bet you know what I mean ;). Oh and if it jumps wildly when you run it, just restart the app, it is some silly bug I will get to later. I have two problems with it. 1) When the speed of the ball is high its motion stops to be smooth and you can basically see him jumping and moving :(. The reason is that to make the illusion of speed I move the ball more and more pixels at a animation-timer-tick. One solution I thought of is to make the number of pixels the ball moves always 1 but instead change the animation timer frequency. The bigger is the frequency the faster will the ball move. Problem is that the regular Win32 timer is too slow for such task and can't move the ball quickly enough. I read the article on CodeProject and figured I should use the multimedia timer. What do you think? Am I on the right path here? 2) The ball flickers.. It is not very visiable but it happens and that means I am doing something wrong. Here's my code to draw the ball (and delete the previous one): void CBall::Draw(int X, int Y) { // Deletes the previous ball draw BitBlt(m_DialogBox.Dc(), m_X, m_Y, m_Size, m_Size, m_Background, 0, 0, SRCCOPY); // Copies the current background BitBlt(m_Background, 0, 0, m_Size, m_Size, m_DialogBox.Dc(), X, Y, SRCCOPY); // Draws the ball Ellipse(m_DialogBox.Dc(), X, Y, X+m_Size, Y+m_Size); m_X = X; m_Y = Y; } Is there some general problem with my way (probably is)? Thank you. P.S How do I activate some [b], [code] etc?? Couldn't find anything it and the post looks ugly =(. :suss: Vitaly Belman :suss:
-
I created a little app where you throw a ball and it bounces. You can see the app here: http://thresholdx.com/misc/Ball.exe To throw the ball, hold the left mouse button, gain some speed and release. I bet you know what I mean ;). Oh and if it jumps wildly when you run it, just restart the app, it is some silly bug I will get to later. I have two problems with it. 1) When the speed of the ball is high its motion stops to be smooth and you can basically see him jumping and moving :(. The reason is that to make the illusion of speed I move the ball more and more pixels at a animation-timer-tick. One solution I thought of is to make the number of pixels the ball moves always 1 but instead change the animation timer frequency. The bigger is the frequency the faster will the ball move. Problem is that the regular Win32 timer is too slow for such task and can't move the ball quickly enough. I read the article on CodeProject and figured I should use the multimedia timer. What do you think? Am I on the right path here? 2) The ball flickers.. It is not very visiable but it happens and that means I am doing something wrong. Here's my code to draw the ball (and delete the previous one): void CBall::Draw(int X, int Y) { // Deletes the previous ball draw BitBlt(m_DialogBox.Dc(), m_X, m_Y, m_Size, m_Size, m_Background, 0, 0, SRCCOPY); // Copies the current background BitBlt(m_Background, 0, 0, m_Size, m_Size, m_DialogBox.Dc(), X, Y, SRCCOPY); // Draws the ball Ellipse(m_DialogBox.Dc(), X, Y, X+m_Size, Y+m_Size); m_X = X; m_Y = Y; } Is there some general problem with my way (probably is)? Thank you. P.S How do I activate some [b], [code] etc?? Couldn't find anything it and the post looks ugly =(. :suss: Vitaly Belman :suss:
You probably want to draw in WM_ERASEBKGRND, but if you want speed, you'll need instead to use DirectX. To post code, use <pre> tags.
this is my code
Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
-
I created a little app where you throw a ball and it bounces. You can see the app here: http://thresholdx.com/misc/Ball.exe To throw the ball, hold the left mouse button, gain some speed and release. I bet you know what I mean ;). Oh and if it jumps wildly when you run it, just restart the app, it is some silly bug I will get to later. I have two problems with it. 1) When the speed of the ball is high its motion stops to be smooth and you can basically see him jumping and moving :(. The reason is that to make the illusion of speed I move the ball more and more pixels at a animation-timer-tick. One solution I thought of is to make the number of pixels the ball moves always 1 but instead change the animation timer frequency. The bigger is the frequency the faster will the ball move. Problem is that the regular Win32 timer is too slow for such task and can't move the ball quickly enough. I read the article on CodeProject and figured I should use the multimedia timer. What do you think? Am I on the right path here? 2) The ball flickers.. It is not very visiable but it happens and that means I am doing something wrong. Here's my code to draw the ball (and delete the previous one): void CBall::Draw(int X, int Y) { // Deletes the previous ball draw BitBlt(m_DialogBox.Dc(), m_X, m_Y, m_Size, m_Size, m_Background, 0, 0, SRCCOPY); // Copies the current background BitBlt(m_Background, 0, 0, m_Size, m_Size, m_DialogBox.Dc(), X, Y, SRCCOPY); // Draws the ball Ellipse(m_DialogBox.Dc(), X, Y, X+m_Size, Y+m_Size); m_X = X; m_Y = Y; } Is there some general problem with my way (probably is)? Thank you. P.S How do I activate some [b], [code] etc?? Couldn't find anything it and the post looks ugly =(. :suss: Vitaly Belman :suss:
That's WM_ERASEBKGND, Christian. That'll cover up the problem with the remnants of windows on the ball. A simple app like yours doesn't need something fancy like DirectX. Keep working at it. Peter O.
-
That's WM_ERASEBKGND, Christian. That'll cover up the problem with the remnants of windows on the ball. A simple app like yours doesn't need something fancy like DirectX. Keep working at it. Peter O.
Peter Occil wrote: That's WM_ERASEBKGND, Christian. *blush* Peter Occil wrote: A simple app like yours doesn't need something fancy like DirectX. Keep working at it. It depends on what sort of speed he wants and what his hardware is. It *probably* does not need DirectX, but that is the way to get maximum speed, nonetheless. Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
-
You probably want to draw in WM_ERASEBKGRND, but if you want speed, you'll need instead to use DirectX. To post code, use <pre> tags.
this is my code
Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
The WM_ERASEBKGND works too.. It improved the flickering a bit. However, didn't make them go completly. Also, it wouldn't be a good idea if I wanted to have a background. What do they use in real 2d games that it moves so nicely? I mean.. Obviously whatevern you can do with DirectX is achievable with regular Win32 functions. :suss: Vitaly Belman :suss:
-
The WM_ERASEBKGND works too.. It improved the flickering a bit. However, didn't make them go completly. Also, it wouldn't be a good idea if I wanted to have a background. What do they use in real 2d games that it moves so nicely? I mean.. Obviously whatevern you can do with DirectX is achievable with regular Win32 functions. :suss: Vitaly Belman :suss:
Vitaly Belman wrote: What do they use in real 2d games that it moves so nicely? DirectX Vitaly Belman wrote: mean.. Obviously whatevern you can do with DirectX is achievable with regular Win32 functions. Obviously not, or why would DX exist at all ? Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002