本文整理汇总了C++中Timer::GetDt方法的典型用法代码示例。如果您正苦于以下问题:C++ Timer::GetDt方法的具体用法?C++ Timer::GetDt怎么用?C++ Timer::GetDt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer::GetDt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
g_SDLwindow = NULL;
g_SDLwindow = SDL_CreateWindow("Tertian", 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT, 0);
sdlApp.Initialize(g_SDLwindow);
XMLFileReader file_reader = XMLFileReader("Data/Animations/test.xml");
//file_reader.OpenFile("Data/Animations/test.xml");
for(int i = 0; i < 10; i++)
cout << file_reader.GetToken("frame", i) << endl;
//set up the animation collection
AnimationCollection ac = AnimationCollection();
ac.InsertAnimation("librarian_attack");
ac.InsertAnimation("librarian_idle");
CubeGrid level = CubeGrid(2,3,2);
// Access array elements
int block_size = 32;
Timer timer;
float delta_time;
string frame_name;
int x = WINDOW_WIDTH/2 + 100;
int y = WINDOW_HEIGHT/2;
while(sdlApp.IsRunning()) {
delta_time = timer.GetDt();
//move the animation frame around
if(Keyboard::GetKey("Up"))
y--;
if(Keyboard::GetKey("Down"))
y++;
if(Keyboard::GetKey("Left"))
x--;
if(Keyboard::GetKey("right"))
x++;
if(Keyboard::GetKey("s"))
ac.StopActiveAnimation();
if(Keyboard::GetKey("a"))
ac.PauseActiveAnimation();
if(Keyboard::GetKey("p"))
ac.PlayActiveAnimation();
//select the active animation
if(Keyboard::GetKey("1"))
ac.SetActiveAnimation("librarian_idle");
if(Keyboard::GetKey("2"))
ac.SetActiveAnimation("librarian_attack");
//get the current animation frame name
frame_name = ac.UpdateActiveAnimation(delta_time);
//blit the animation frame
Graphics::BlitImage(frame_name, x, y);
Graphics::Print("[S]top animation.", 0, 12);
Graphics::Print("P[a]use animation.", 0, 24);
Graphics::Print("[P]lay animation.", 0, 36);
Graphics::Print("Select animation [1]/[2] ", 0, 48);
Graphics::DrawLevelBlock(WINDOW_WIDTH/2, WINDOW_HEIGHT/2);
Graphics::DrawLevelBlock(WINDOW_WIDTH/2 + 128, WINDOW_HEIGHT/2);
Graphics::DrawLevelBlock(WINDOW_WIDTH/2 - 128, WINDOW_HEIGHT/2);
Graphics::DrawLevelBlock(WINDOW_WIDTH/2 - 64, WINDOW_HEIGHT/2 - 32);
Graphics::DrawLevelBlock(WINDOW_WIDTH/2 + 64, WINDOW_HEIGHT/2 - 32);
Graphics::DrawLevelBlock(WINDOW_WIDTH/2 + 64, WINDOW_HEIGHT/2 - 53);
Graphics::DrawLevelBlock(WINDOW_WIDTH/2, WINDOW_HEIGHT/2 - 64);
Graphics::SetDrawColor();
for(int i = 0; i < level.GetSizeX(); i++)
for(int j = 0; j < level.GetSizeY(); j++)
for(int k = 0; k < level.GetSizeZ(); k++){
int value = level.GetCell(i,j,k);
Graphics::Print(value, block_size * i , block_size * j + 120 * k);
}
sdlApp.Update(timer.GetDt());
#if _DEBUG
//.........这里部分代码省略.........