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

Attaching right mouse click to cast spell


The right mouse click will have to go through quite a few function calls before calling the avatar's CastSpell method. The call graph would look something like the following screenshot:

A few things happen between right click and spell cast. They are as follows:

  • As we saw before, all user mouse and keyboard interactions are routed through the Avatar object. When the Avatar object detects a right-click, it will pass the click event to HUD through AAvatar::MouseRightClicked().

  • Recall from Chapter 10, Inventory System and Pickup Items where we used a struct Widget class to keep track of the items the player had picked up. struct Widget only had three members:

    struct Widget
    {
      Icon icon;
      FVector2D pos, size;
      ///.. and some member functions
    };

    We will need to add an extra property for struct Widget class to remember the spell it casts.

    The HUD will determine if the click event was inside Widget in AMyHUD::MouseRightClicked().

  • If the click was on the Widget...