PacMan Movement isn't smooth
I am moving pacm开发者_开发知识库an in a line using simple for loop but the pacman blinks or may be its the whole screen updating and blinking. How can i make it more smooth?
Edit:
I am currently using C++ Turbo and its built in graphics library. BUt i tend to use SDL later (using image tiles over a 2D array (grid)).
There are many techniques you can use for smooth transition between frames. Probably the simplest is double buffering where the construction of a frame is done outside of the viewable video memory, then the whole block of memory is switched to the new frame location (usually with page flipping, a fast hardware switch, but even creating the frame in non-video-memory and "blitting" it to video memory in one fast operation can be advantageous).
By using this method the transition can seem much smoother since you never have a half-built frame displayed at any point. This is especially so if the switch is made between hardware frames (at least on older CRT monitors - I actually don't know if the newer monitors even have a concept of vertical and horizontal retrace).
Another method is to ensure the calculation cost per frame is low. An example is only drawing the tunnel lines in PacMan once in non-video-memory so you can "blit" it relatively fast (because they never change). In other words, constructing a frame would consist of:
- copying the tunnel walls, which never change.
- copying the dots, which change rarely.
- drawing the characters, which change fairly frequently.
That speeds up the process quite a bit, I've used this trick on look-down space shooter games so that deeper frames can move slower as well, giving a parallax effect.
精彩评论