- OpenGL Game Development By Example
- Robert Madsen Stephen Madsen
- 510字
- 2021-07-16 12:44:23
Spritely speaking
Many years ago, a computer geek invented a cool way to render and display small images on a computer screen. These images would move around on the screen and even collide with other objects. The computer geek called these images sprites, and that name has stuck ever since.
Sprites versus non-sprites
A sprite is simply an image that represents an object on the screen. Examples of sprites include characters, NPCs, weapons, alien spaceships, and rocks. Anything that can move on the screen or be hit by another object in the game is a sprite. Objects that don't interact with other objects aren't sprites. Examples might include mountains in the background, the ground, and the sky.
Obviously, it takes both sprites and non-sprites to implement a game. Also, the distinction is a little arbitrary. Some games implement all of the images in the game as sprites because it is more convenient to treat all images in the game in a consistent manner.
Flipbook animation
Did you ever create a flipbook when you were a kid? To jog your memory, here is how it worked. First, you sketched a simple figure on a notepad. Then you went to the next page and sketched the same image, but this time something was slightly different. You continued sketching images that were slightly different from the original on successive pages. When you were done, you flipped the pages at the notebook edge and saw what appeared to be a rudimentary movie.

Another example is a movie. Movies are recorded on film as frames. The film is then run through a projector, which plays the film back one frame at a time. The key, as mentioned before, is to play frames back at least 24 frames per second to fool the eye into thinking that there is fluid motion.
Framed animation
2D sprite animation works much like a flipbook. An artist draws successive versions of an image. When the images are rendered one after another, it appears to move. Each image in an animation is called a frame. It takes at least 24 or more fps to create a convincing animation. Obviously, more frames will create a smoother animation.

The preceding image illustrates a very simple animation using four frames. The only thing that changes is the robot's arm position. Played in sequence from Frame 1 through Frame 4, the arm would appear to swing from the front to the back and then forward again. If this was combined with moving the sprite to the right, then you would get a very simple animation of a walking robot.
Tip
As the preceding example illustrates, I am not an artist! I am a coder, so the art created for this book will be very simple. It is actually common for very simple placeholder art to be used in the initial stages of a game. This allows the programmers to test features of the game while the art team is working on the real art that will be put in the game at a later stage.
- Android NDK Game Development Cookbook
- 基于ARM的嵌入式系統和物聯網開發
- 現代辦公設備使用與維護
- 單片機原理及應用系統設計
- Apple Motion 5 Cookbook
- 分布式微服務架構:原理與實戰
- Intel Edison智能硬件開發指南:基于Yocto Project
- Blender Quick Start Guide
- 深入理解序列化與反序列化
- Arduino項目開發:智能生活
- 基于網絡化教學的項目化單片機應用技術
- 單片機原理與技能訓練
- 計算機組裝與維護(慕課版)
- 分布式存儲系統:核心技術、系統實現與Go項目實戰
- Practical Artificial Intelligence and Blockchain