Creating A Simple Moving Text Animation
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Creating A Simple Moving Text Animation

  1. #1
    Join Date
    Jun 2009
    Posts
    118

    Creating A Simple Moving Text Animation

    I want to make my window when I click a button, slide off screen. I can easily do this by going x - 1 until its off screen, but what I want, is to make it like faster to slower motion moving in a left or right direction.

    I think this can be done with the power function, Ive tried but its just going straight at a constant speed everytime.

    Code:
                            //Function begin
    bool hideWindow(int iWindow, double interval, int direction){
                            static double res = 0.99;
    
    			static double iTime = timeGetTime() + interval;
    			int iPresent = timeGetTime();
    			
    			if (iPresent > iTime) // timer went off
    			{
    				res = pow(res, res);
    				iTime = double(timeGetTime()) +  res * interval; // reset the timer and make the new timer less time to make it faster
    				window[iWindow].x += direction; // move left or right by x pixels
    			}
                            if (window[iWindow].x > SCREEN_WIDTH) // process complete
                                 return true;
                            return false; // process incomplete and the function will be recalled from main
    }


    This looks right to me,Its being called each frame, and my window is moving in the right direction until its off screen but i Need to change the speed.

    Thanks if you have any ideas/modifications to what I have.

  2. #2
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: Creating A Simple Moving Text Animation

    Or simply you could create a video and show it on your screen using video APIs.
    Regards,
    Ramkrishna Pawar

  3. #3
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: Creating A Simple Moving Text Animation

    Hi Roger,

    I see a couple of things:

    1 - The speed of the window movement will be inversely proprtional to res, which will converge to 1. So, the speed will change from 0.99 to 1.0, which will not really be noticable.

    2 - The value returned by timeGetTime() will only change every 5 milliseconds or so. I don't know what you've chosen for the value of interval, but it will need to be quite a bit higher than 5 milliseconds, or the window movement will just be every 5 milliseconds, regardless of how you calculate res.

    pow() is probably a good function to use, since the rate of convergence to 1 will slow markedly as it approaches. However, you need to find a way to make the speed of the window relative to the rate of convergence, not the absolute value. One way to do that would be to something like:
    Code:
    double speed;
    ......
    speed = - res;
    res = pow(res,res);
    speed +=  res;
    and then use the inverse of speed rather than res when setting up your timer value.
    Alan
    Last edited by alanjhd08; July 9th, 2009 at 07:54 AM. Reason: Had the relationship between speed and res wrong.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center