1

我正在使用简单的 for 循环将 pacman 移动到一条线上,但 pacman 会闪烁,或者可能是整个屏幕更新和闪烁。我怎样才能使它更光滑?

编辑:

我目前正在使用 C++ Turbo 及其内置的图形库。但是我倾向于稍后使用 SDL(使用二维数组(网格)上的图像块)。

4

1 回答 1

4

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.

于 2010-12-27T12:19:12.717 回答