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


C++ Input::Update方法代码示例

本文整理汇总了C++中Input::Update方法的典型用法代码示例。如果您正苦于以下问题:C++ Input::Update方法的具体用法?C++ Input::Update怎么用?C++ Input::Update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Input的用法示例。


在下文中一共展示了Input::Update方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_ui

int test_ui(int argc, char **argv){
	bool quit=false;
	Input inputs;
	Timer::Update();

	Window *awin = static_cast<Window*>(UI::Add(new Window(0,0,200,400,"A Window")));
	Tabs *tabcont = static_cast<Tabs*>(awin->AddChild(new Tabs(5,25,180,300,"Tabs")));
	Tab *tab1 = static_cast<Tab*>(tabcont->AddChild(new Tab("Tab1")));
	Tab *tab2 = static_cast<Tab*>(tabcont->AddChild(new Tab("Tab2")));

	tab1->AddChild(new Picture(50,100,50,50,"Resources/Graphics/corvet.png"));
	tab1->AddChild(new Checkbox(10,120,true,"Hello"));
	tab1->AddChild(new Button(100,300,50,20,"A button"));
	tab1->AddChild(new Button(100,340,50,20,"A button2"));
	
	tab2->AddChild(new Slider(5,20,100,20,"Slider"));
	tab2->AddChild(new Textbox(5,50,100,1,"Hello","Textbox"));
	tab2->AddChild(new Label(5,80,"Hello"));
	
	while( !quit ) {
		quit = inputs.Update();
		
		Timer::Update();

		Video::Erase();

		UI::Draw();
		Video::Update();
		Timer::Delay();
	}
	return 0;
}
开发者ID:DuMuT6p,项目名称:Epiar,代码行数:32,代码来源:ui.cpp

示例2: MainLoop

void WolfEngine::MainLoop()
{
    int quit = 0;
    SDL_Event eventHandler;
    Uint32 curFrameTime = 0;
    Uint32 lastFrameTime = 0;
    Input input;

	//glEnable(GL_CULL_FACE);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    while (!quit)
    {
        curFrameTime = SDL_GetTicks();
        
        Time::frameTimeS = (float)(curFrameTime - lastFrameTime) / 1000;
        
        // Clear the screen
		glClearColor ( 0.392, 0.584, 0.929, 1.0 );
		glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        input.Update(&eventHandler);
        
        if (eventHandler.type == SDL_WINDOWEVENT_RESIZED)
        {
            scene->camera->width = eventHandler.window.data1;
            scene->camera->height = eventHandler.window.data2;
        }
        
        if (eventHandler.type == SDL_QUIT)
        {
            quit = 1;
        }
        
        scene->Update();
        
        //Update the gameObjects
        scene->UpdateObjects();

		scene->camera->UpdateMatrices();
        
        //Render the SpriteRenderers
        scene->RenderObjects();
        
        //Late update
        scene->LateUpdateObjects();

        lastFrameTime = curFrameTime;

		SDL_GL_SwapWindow(window);
        
        if (maxFPS != -1 && SDL_GetTicks() - curFrameTime < 1000 / maxFPS)
            SDL_Delay((1000 / maxFPS) - (SDL_GetTicks() - curFrameTime));
    }
	Quit();
}
开发者ID:Wolfos,项目名称:WolfEngine,代码行数:57,代码来源:WolfEngine.cpp

示例3: GameLoop

/**\brief Simple Game loop.*/
void Test::GameLoop( void ){
	bool quit=false;
	Input inputs;
	Timer::Update();
	while( !quit ) {
		quit = inputs.Update();
		
		int logicLoops = Timer::Update();
		while(logicLoops--) {
				// Update cycle
		}

		Video::Erase();
		Video::Update();
		UI::Draw();
		Timer::Delay();
	}
}
开发者ID:Maka7879,项目名称:Epiar,代码行数:19,代码来源:tests.cpp

示例4: GameLoop

// Game Loop 
void Game::GameLoop( )
{
	Graphics graphics;
	Input input;
	SDL_Event sdlEvent;
	m_Player = Player( graphics, 280.f, 252.f );
	m_Level = Level( "Level1", Vector2( 100, 100 ), graphics );

	float lastUpdateTime = SDL_GetTicks( );	

	while( true )
	{
		// Update input
		input.Update( );

		// SDL Events
		if ( SDL_PollEvent( &sdlEvent ) )
		{
			// Key is down
			if ( sdlEvent.type == SDL_KEYDOWN )
			{				
				// is it repeating
				if ( sdlEvent.key.repeat == 0 )
				{
					input.KeyDownEvent( sdlEvent );
				}
			}
			// Key is released
			else if ( sdlEvent.type == SDL_KEYUP )
			{
				input.KeyUpEvent( sdlEvent );
			}
			// User quits
			else if ( sdlEvent.type == SDL_QUIT )
			{
				return;
			}
		}

		// Quit if escape is pressed
		if ( input.WasKeyPressed( SDL_SCANCODE_ESCAPE ) )
		{
			return;
		}

		// Player character 
		if ( input.IsKeyHeld( SDL_SCANCODE_LEFT ) || input.IsKeyHeld( SDL_SCANCODE_A ) )
		{
			m_Player.MovePlayer( Direction::LEFT );
		}
		else if ( input.IsKeyHeld( SDL_SCANCODE_RIGHT ) || input.IsKeyHeld( SDL_SCANCODE_D ) )
		{
			m_Player.MovePlayer( Direction::RIGHT );
		}
		else
		{
			m_Player.StopMoving( );
		}

		// Jump
		if ( input.WasKeyPressed( SDL_SCANCODE_SPACE ) )
		{
			m_Player.Jump( );
		}

		// Debug
		bDrawDebug = ( input.IsKeyHeld( SDL_SCANCODE_5 ) ) ? true : false;

		const float CURRENT_TIME_IN_MS = SDL_GetTicks( );
		float elapsedTimeInMS = CURRENT_TIME_IN_MS - lastUpdateTime;
		lastUpdateTime = CURRENT_TIME_IN_MS;

		Tick( std::fmin( elapsedTimeInMS, GameStats::MAX_FRAME_TIME ) ); 
		Draw( graphics );
	}

	SDL_Quit( );
}
开发者ID:Vawx,项目名称:CaveStory_Remake_SDL,代码行数:79,代码来源:Game.cpp

示例5: WinMain

/*
=======
WinMain
=======
*/
int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int nCmdShow ) {
	HWND hwnd;
    MSG  msg;	

	/* Initialise and create window */
	hwnd = CreateOurWindow( "Mirrors and Shadows", S_WIDTH, S_HEIGHT, 0, false, hInstance );	
	if( hwnd == NULL ) return true;

	/* Initialise OpenGL and other settings */
	Init( hwnd );

	/* Create the OpenGLApplication */
	OpenGLApplication theApplication( mInput, mCamera );
	theApplication.Init();

	/* Main Loop */
	while( true ) {							
		if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
		    if( msg.message == WM_QUIT ) {
				break;
			}
			TranslateMessage( &msg );							
			DispatchMessage( &msg );
		/* Render Scene */
		} else {
			/* Update Input and Camera */
			mInput.Update();
			mCamera.Update();

			/* Switch to WireFrame */
			if( mInput.mKeys[ VK_SPACE ] ) {
				glPolygonMode( GL_FRONT, GL_LINE );
			} else {
				glPolygonMode( GL_FRONT, GL_FILL );
			}

			/* Display Controls */
			if( mInput.mKeys[ VK_CONTROL ] ) {
				theApplication.mDisplayControls = true;
			} else {
				theApplication.mDisplayControls = false;
			}

			/* Start OpenGl - clear buffers & load identity matrix */
			glClearStencil( 0 );
			glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); 
			glLoadIdentity(); 

			/* Set our viewpoint - the camera */
			gluLookAt( mCamera.mPosition.x, mCamera.mPosition.y, mCamera.mPosition.z,                      // where we are
			           mCamera.mPointOfInterest.x, mCamera.mPointOfInterest.y, mCamera.mPointOfInterest.z, // what we look at
			           mCamera.mUp.x, mCamera.mUp.y, mCamera.mUp.z );                                      // which way is up

			/* Render the Application */
			theApplication.Render();

			/* End OpenGL - swap the frame buffers */
			SwapBuffers( ghdc ); 
		}
    }

	return msg.wParam ;										
}
开发者ID:McBainC,项目名称:Portfolio,代码行数:68,代码来源:Main.cpp

示例6: _tWinMain

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	Engine::Init();

	Input input;
	input.Init();

	Window window;
	window.Init(800, 600, "killerg2d");

	ResMgr resmgr;
	resmgr.Init();
	
	FrameRate framerate;
	framerate.Init(600);

	Timer timer;
	timer.Init();

	SpiritAnimate spirit;
	spirit.Init("abc.txt");


	int x = 100, y = 100;
	int model = 0;
	while( !input.IsKeyDown(SDLK_ESCAPE) )
	{
		timer.Update();

		input.Update();

		if( input.IsKeyDown(SDLK_LEFT) )
			x-=1;

		if( input.IsKeyDown(SDLK_RIGHT) )
			x+=1;

		if( input.IsKeyDown(SDLK_UP) )
			y-=1;

		if( input.IsKeyDown(SDLK_DOWN) )
			y+=1;

		if( input.IsKeyDown(SDLK_x) )
			spirit.Play();

		if( input.IsKeyDown(SDLK_y) )
			spirit.Stop();

		spirit.Update(timer.GetIntervalF());

		window.Clear();

		spirit.Draw(&window, x, y);

		window.Flush();

		framerate.WaitFrame();
	}

	timer.Destroy();

	framerate.Destroy();

	resmgr.Destroy();

	window.Destroy();

	input.Destroy();


	Engine::Destroy();


	
}
开发者ID:killgxlin,项目名称:killerg2d,代码行数:79,代码来源:killerg_nc.cpp

示例7: RunState


//.........这里部分代码省略.........
		float step_turns = std::min(TIME_SCALE * MOTIONBLUR_TIME * sim_rate, 1.0f) / MOTIONBLUR_STEPS;

		// advance to beginning of motion blur steps
		sim_fraction += frame_turns;
		sim_fraction -= MOTIONBLUR_STEPS * step_turns;

		// for each motion-blur step
		for (int blur = 0; blur < MOTIONBLUR_STEPS; ++blur)
		{
			// clear the screen
			glClear(
				GL_COLOR_BUFFER_BIT
#ifdef ENABLE_DEPTH_TEST
				| GL_DEPTH_BUFFER_BIT
#endif
				);

			// set projection
			glMatrixMode( GL_PROJECTION );
			glLoadIdentity();
			glFrustum( -0.5*VIEW_SIZE*SCREEN_WIDTH/SCREEN_HEIGHT, 0.5*VIEW_SIZE*SCREEN_WIDTH/SCREEN_HEIGHT, 0.5f*VIEW_SIZE, -0.5f*VIEW_SIZE, 256.0f*1.0f, 256.0f*5.0f );

			// set base modelview matrix
			glMatrixMode( GL_MODELVIEW );
			glLoadIdentity();
			glTranslatef( 0.0f, 0.0f, -256.0f );
			glScalef( -1.0f, -1.0f, -1.0f );

			// advance the sim timer
			sim_fraction += step_turns;

			if (escape)
			{
				input.Update();
				input.Step();
			}
			// while simulation turns to run...
			else while ((singlestep || !paused) && sim_fraction >= 1.0f)
			{
				// deduct a turn
				sim_fraction -= 1.0f;
				
				// advance the turn counter
				++sim_turn;

				// save original fraction
				float save_fraction = sim_fraction;

				// switch fraction to simulation mode
				sim_fraction = 0.0f;

#ifdef COLLECT_DEBUG_DRAW
				// collect any debug draw
				glNewList(debugdraw, GL_COMPILE);
#endif

				// seed the random number generator
				Random::Seed(0x92D68CA2 ^ sim_turn);
				(void)Random::Int();

				// update database
				Database::Update();

				if (curgamestate == STATE_PLAY)
				{
					if (playback)
开发者ID:Fissuras,项目名称:videoventure,代码行数:67,代码来源:Run.cpp

示例8: main


//.........这里部分代码省略.........
			{
				if (a < 255)
				{
					a += 1;
				}

				titleFadeIn.restart();
			}


			sprTitleText.setColor(sf::Color(255, 255, 255, a));
			
			window.draw(sprTitleBack);
			window.draw(sprTitleText);
			window.display();

			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Return))
			{
				gState = Main;
			}

		}


		while (gState == Main)
		{

			float dt = deltaClock.restart().asSeconds();
			//Delta time decouples from frame rate

			if (dt > 1.0f / 60.0f)
				//If the next frame is higher than 1 in 60 - the cap stops it from going further e,g window is held
			{
				dt = 1.0f / 60.0f;
			}

			sf::Event event;
			while (window.pollEvent(event))
			{
				if (event.type == sf::Event::Closed)
					window.close();
			}

			//Clear Screen
			window.clear();

			input.Update(dt);

			//Red Circle Movement
			for (int i = 0; i < circlecount; i++)
			{
				sf::Vector2f movelose((rand() % 5) - 2, (rand() % 5) - 2);
				sf::Vector2f currentposition(tanks[i].GetPosition());

				tanks[i].SetPosition((movelose * dt * tanks[i].MoveSpeed()) + currentposition);
			}

			// UPDATE LOOP
			for (int i = 0; i < circlecount; ++i)
			{
				tanks[i].Update(dt);
			}
			playerTank.Update(dt);

			//Draw Loop for red circles
			for (int i = 0; i < circlecount; i++)
			{
				if (tanks[i].GetDrawable() != NULL)
				{
					window.draw(*tanks[i].GetDrawable());
					window.draw(tanks[i].getBounds());
				}
			}


			// Draw player
			//window.draw(*playerTank.GetDrawable());
			//window.draw(playerTank.getBounds());
			playerTank.Draw(&window);
			window.draw(circleTest);
			window.draw(circleColSquare);

			window.display();

			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape))
			{

				window.close();
			}
		}
		//EndMainLoop

	}





	return 0;
}
开发者ID:Gerahn,项目名称:SFMLTanks,代码行数:101,代码来源:Main.cpp

示例9: Run

bool Simulation::Run( void ) {
	bool quit = false;
	Input inputs;
	int fpsCount = 0; // for FPS calculations
	int fpsTotal= 0; // for FPS calculations
	Uint32 fpsTS = 0; // timestamp of last FPS printing

	// Grab the camera and give it coordinates
	Camera *camera = Camera::Instance();
	camera->Focus(0, 0);

	// Generate a starfield
	Starfield starfield( OPTION(int, "options/simulation/starfield-density") );

	// Create a spritelist
	SpriteManager sprites;

	Player *player = Player::Instance();

	// Set player model based on simulation xml file settings
	player->SetModel( models->GetModel( playerDefaultModel ) );
	sprites.Add( player->GetSprite() );

	// Focus the camera on the sprite
	camera->Focus( player->GetSprite() );

	// Add the planets
	planets->RegisterAll( &sprites );

	// Start the Lua Universe
	Lua::SetSpriteList( &sprites );
	Lua::Load("Resources/Scripts/universe.lua");

	// Start the Lua Scenarios
	Lua::Run("Start()");

	// Ensure correct drawing order
	sprites.Order();
	
	// Create the hud
	Hud::Hud();

	Hud::Alert( "Captain, we don't have the power! Pow = %d", 3 );

	fpsTS = Timer::GetTicks();
	// main game loop
	while( !quit ) {
		quit = inputs.Update();
		
		if( !paused ) {
			Lua::Update();
			// Update cycle
			starfield.Update();
			camera->Update();
			sprites.Update();
			camera->Update();
			Hud::Update();
			UI::Run(); // runs only a few loops
			
			// Keep this last (I think)
			Timer::Update();
		}

		// Erase cycle
		Video::Erase();
		
		// Draw cycle
		starfield.Draw();
		sprites.Draw();
		Hud::Draw( sprites );
		UI::Draw();
		Video::Update();
		
		// Don't kill the CPU (play nice)
		Timer::Delay();
		
		Coordinate playerPos = player->GetWorldPosition();

		// Counting Frames
		fpsCount++;
		fpsTotal++;

		// Update the fps once per second
		if( (Timer::GetTicks() - fpsTS) >1000 ) { 
			Simulation::currentFPS = static_cast<float>(1000.0 *
					((float)fpsCount / (Timer::GetTicks() - fpsTS)));
			fpsTS = Timer::GetTicks();
			fpsCount = 0;
		}
	}

	Log::Message("Average Framerate: %f Frames/Second", 1000.0 *((float)fpsTotal / Timer::GetTicks() ) );
	return true;
}
开发者ID:moses7,项目名称:Epiar,代码行数:94,代码来源:simulation.cpp


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