Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. First steps in animation.. Kinda

First steps in animation.. Kinda

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestioncomperformancediscussion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vitaly Belman
    wrote on last edited by
    #1

    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:

    C P 2 Replies Last reply
    0
    • V Vitaly Belman

      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:

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      V 1 Reply Last reply
      0
      • V Vitaly Belman

        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:

        P Offline
        P Offline
        Peter Occil
        wrote on last edited by
        #3

        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.

        C 1 Reply Last reply
        0
        • P Peter Occil

          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.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • C Christian Graus

            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

            V Offline
            V Offline
            Vitaly Belman
            wrote on last edited by
            #5

            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:

            C 1 Reply Last reply
            0
            • V Vitaly Belman

              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:

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups