HGE tutorial06

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
bool FrameFunc()
{
    float dt = hge->Timer_GetDelta();
    static float t = 0.0f;
    float tx, ty;
    int id;
    static int lastid = 0;
 
    // If ESCAPE was pressed, tell the GUI to finish
    if (hge->Input_GetKeyState(HGEK_ESCAPE)) { lastid = 5; gui->Leave(); }
 
    // We update the GUI and take an action if
    // one of the menu items was selected
    id = gui->Update(dt);
    if (id == -1)
    {
        switch (lastid)
        {
        case 1:
        case 2:
        case 3:
        case 4:
            gui->SetFocus(1);
            gui->Enter();
            break;
 
        case 5: return true;
        }
    }
    else if (id) { lastid = id; gui->Leave(); }
 
    // Here we update our background animation
    t += dt;
    tx = 50 * cosf(t / 60);
    ty = 50 * sinf(t / 60);
 
    quad.v[0].tx = tx;        quad.v[0].ty = ty;
    quad.v[1].tx = tx + 800 / 64; quad.v[1].ty = ty;
    quad.v[2].tx = tx + 800 / 64; quad.v[2].ty = ty + 600 / 64;
    quad.v[3].tx = tx;        quad.v[3].ty = ty + 600 / 64;
 
    return false;
}

在这个代码中,当gui->update(dt)之后,会进行动画的操作。关于gui->update(dt):

If one of the controls has changed it's state, Update returns that control's identificator. If leave method was called and all the controls have finished their animation, Update returns -1. Otherwise it returns 0.

按照这个解释,我们会遇到三种情况:

1)、指向了某个选项,但是没有选择,那么 return  0;

2)、指向并选择了某个选项,那么 return id; 之后会调用leave();然后选项会消失在屏幕上

3)、在2)之后的情况,调用leave()之后会立刻的 return -1。那么在return -1则会默认指向某个选项,并且会刷新使得选项出现。

将原来的if-else if改成了if-else if-else输出了当前指示的选项。

posted @   YORU  阅读(208)  评论(0编辑  收藏  举报
编辑推荐:
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
阅读排行:
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· Vite CVE-2025-30208 安全漏洞
· 《HelloGitHub》第 108 期
· MQ 如何保证数据一致性?
· 一个基于 .NET 开源免费的异地组网和内网穿透工具
点击右上角即可分享
微信分享提示