Book Image

Learning C++ by creating games with UE4

By : William Sherif
Book Image

Learning C++ by creating games with UE4

By: William Sherif

Overview of this book

Table of Contents (19 chapters)
Learning C++ by Creating Games with UE4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Variables and Memory
Index

Drawing the player inventory


An inventory screen in a game such as Diablo features a pop-up window, with the icons of the items you've picked up in the past arranged in a grid. We can achieve this type of behavior in UE4.

There are a number of approaches to drawing a UI in UE4. The most basic way is to simply use the HUD::DrawTexture() calls. Another way is to use Slate. Another way still is to use the newest UE4 UI functionality: Unreal Motion Graphics (UMG) Designer.

Slate uses a declarative syntax to lay out UI elements in C++. Slate is best suited for menus and the like. UMG is new in UE 4.5 and uses a heavily blueprint-based workflow. Since our focus here is on exercises that use C++ code, we will stick to a HUD::DrawTexture() implementation. This means that we will have to manage all the data that deals with the inventory in our code.

Using HUD::DrawTexture()

We will achieve this in two steps. The first step is to push the contents of our inventory to the HUD when the user presses the...