- CryENGINE Game Programming with C++,C#,and Lua
- Filip Lundgren Ruan Pearce-Authers
- 614字
- 2025-02-25 18:32:14
The stock flownode overview
To make something a little more complex, we're going to need an understanding of what nodes the CryENGINE provides for us by default.
Building a clock
One of the most useful nodes we have access to, at least for debugging purposes, is the HUD:DisplayDebugMessage node. It allows you to display information in the game window, optionally with a timeout. With that in mind, let's build a little debug clock based on the time information we learnt about earlier.
The Time:TimeOfDay node outputs the current time in the CryENGINE time format, which is defined as hours plus minutes divided by 60. For example, 1:30 p.m. would be expressed as 13.5 in CryENGINE time. We now know we're going to need some mathematical operations, so it's time to check the Math flownode category.
The first thing we'll do is get the time in hours by rounding the current time down. To do this, place Math:Floor, then connect the CurTime output from our Time:TimeOfDay node to Floor's A input port. Then, feed this into a Debug Message node:

Jump into game right now, and you should see the current time in hours displayed on your screen.
We then need to subtract our new value from our original to get the minutes portion. To do this, we need Math:Sub to subtract the rounded hours from the original CurTime value. After that, a Math:Mul node will scale up the new time by 60, so your graph should look like this:

Remember to set posY of the second Debug node to move it down which will enable you to see both at the same time.
If you jump in game again, you should now see the current hours and minutes printed!
Listening for player input
What if now, we wanted to allow the player to test moving through different times of the day? Generally speaking, it's the easiest way to set up a key listener, where we fire an event when a certain key is pressed. Fortunately CryENGINE encapsulates this functionality nicely into a single node, Input:Key.
Let's now set it up so that pressing the P key will make time move extremely fast, and that pressing O will stop it again.
We need to set the Speed value of our Time:TimeOfDay node, but in this case, we'll also need to feed two values in! CryENGINE provides a node called Logic:Any that features multiple input ports and just passes on any data given to it, which we can use here to receive both input values. We use two key nodes which call Math:SetNumber nodes, and the Logic:Any node then relays this information to our Time:TimeOfDay node, as well as calling SetSpeed:

Jump in game now, and press P to start the day moving! Press O again, and the time of day should freeze.
Executing on a loop
You might have noticed that our clock isn't updating correctly any more. This is because most nodes won't output data unless triggered; in this case, we'll get no output if we don't trigger either GetTime or SetTime. We have two options for calling this: we can either use Time:Time to execute it every frame, or Time:Timer.
The latter can control the granularity of the tick, but in this case, we probably want it to be updated every frame while moving fast, so let's keep it simple. Connect the tick output to our GetTime input, and our clock should be updating correctly once again!
