i have abitmap loaded in from file, for example a picture of a car. want to make the car move accros the screen. any tips?
01-08-2006, 05:55 AM
Basically, you will need to run a loop that runs for the duration of the program. Use a variable to keep track of the cars position on the screen. In the loop, you first blank out the screen, then move the variable up a bit, then draw the car at the position designated by the variable.
The problem with this is that the speed will depend on the speed of the computer, and the car will move to fast on a good computer.
So for a more advanced program, use a function that gets the system time (if your using GLUT, SDL or equivalent, then use their function, otherwise use a system call (i.e. time() in time.h)). Then calculate the time difference between iterations of the loop, scale the result to whatever speed you want and then add the result to the variable for the cars position rather than use a static increment. This will produce a speed that is consistent on computers, even if the computer is to slow the animation will be laggy rather than slow.
Hope this helps.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.