Using sprites
To develop any 2D game, we need sprites. Sprites are elements of computer graphics that can stay on screen, be manipulated, and be animated. GDI allows us to use sprites to create our game. Probably all the assets in the game will be sprites, from the UI to the main characters, and so on.
Getting ready
For this recipe, you will need a Windows machine with a working copy of Visual Studio.
How to do it…
In this recipe, we will find out how to use sprites in our game:
Open Visual Studio.
Create a new C++ project.
Create a new resource type.
Select the Sprite option as the new resource type.
Add the following source files:
backbuffer.h/cpp
,Clock.h/cpp
,Game.h/.cpp
,sprite.h/cpp
, andUtilities.h
.Add the following lines of code to
backbuffer.h
:#pragma once #if !defined(__BACKBUFFER_H__) #define __BACKBUFFER_H__ // Library Includes #include <Windows.h> // Local Includes // Types // Constants // Prototypes class CBackBuffer { // Member Functions public: CBackBuffer(); ~CBackBuffer...