标签:style blog http io os strong sp div 2014
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输出了当前指示的选项。
标签:style blog http io os strong sp div 2014
原文地址:http://www.cnblogs.com/yoru/p/4028246.html