当前位置: 首页>>代码示例>>C++>>正文


C++ Timer::GetDt方法代码示例

本文整理汇总了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
//.........这里部分代码省略.........
开发者ID:Hypervariate,项目名称:tertian,代码行数:101,代码来源:main.cpp


注:本文中的Timer::GetDt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。