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


C++ Clock::getElapsedTime方法代码示例

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


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

示例1: drawtimer

// Draws just the timer 
void ScoreBar::drawtimer(sf::RenderWindow &window, sf::Clock &clock)
{
	string str;

	str = "Clock: " + std::to_string(30 - int(clock.getElapsedTime().asSeconds()));
	timer.setString(str);

	window.draw(timer);
}
开发者ID:nathanyoung1,项目名称:spiderkiller,代码行数:10,代码来源:ScoreBar.cpp

示例2: Display

void FPSCounter::Display(sf::RenderTarget * app, unsigned int frameCount, sf::Clock & clock)
{
    impl->fc++;
    if(impl->fc > 99)
    {
        SetText( impl->getNewText(clock.getElapsedTime().asMicroseconds()) );
    }
    TextObject::Display(app, frameCount, clock);
}
开发者ID:gergondet,项目名称:bci-interface,代码行数:9,代码来源:FPSCounter.cpp

示例3: draw

void Game_Manager::draw()
{
    static sf::Clock render_clock;
    if (render_clock.getElapsedTime().asMilliseconds() < 2) {
        return;
    }
    render_clock.restart();
    m_app->clear();

    if (is_tree)
    {
        tree_background.draw(0, 0);
        skill_button[0].draw();
        skill_button[3].draw();
        skill_button[4].draw();
        skill_button[5].draw();
        skill_button[6].draw();
        skill_button[7].draw();
        skill_button[8].draw();

        energy_text.refill(to_string(myPlayer.getEnergy()));
        energy_text.draw(0, 0, 55);
        if (skill_level < 3)
        {
            empty.draw(0, 500);
        }
        else if (skill_level >= 3)
        {
            empty.draw(0, 700);
        }
    }
    else if (is_menu_visible)
    {
        menu1.draw();
    }
    else
    {
        m_app->setView(m_view2);
        //Changes on the world
        world_sprite.draw(0, 0);
        afficherMapobjet();

        m_app->setView(m_view1);

        //Changes on the HUD, player
        myPlayer.draw();
        light_bar_background.draw(m_screen_x - light_bar_background.get_w(), 0);
        light_bar.draw(m_screen_x + 28 - light_bar_background.get_w(), 40);
        light_bar_grad.draw(m_screen_x - light_bar_background.get_w(), 0);
        energy_text.refill(to_string(myPlayer.getEnergy() ) );
        energy_text.draw(0, 0, 55);
        difficulter_text.refill(to_string(_difficulter-1));
        difficulter_text.draw(0, 100, 55);
    }
    m_app->display();
}
开发者ID:Sigaur,项目名称:Project-obscurity,代码行数:56,代码来源:Game_Manager.cpp

示例4: comportamiento

void Boss::comportamiento(Personaje* s, Mapa *map){
    
   
    if(clock_comportamiento.getElapsedTime().asMilliseconds()>4000)      
    { srand(time(NULL));
        int num = rand()%2;
    actitud=num;
    clock_comportamiento.restart();         
    }
    if(actitud==0){
    if(detectada && !muriendo){
        if(!rapido){ this->set_speed(fast); rapido = true;}
        int distancia = this->pos->getX() - s->getPosicion()->getX();
        if(distancia > 0){ 
            if(distancia < 15){ this->attack(s); }
            else{ this->atacando = false; this->orientacion = 1;}
        }
        else{
            if(distancia > -15){ this->attack(s); }
            else{ this->atacando = false; this->orientacion = 0;}
        }
        
        int aux = this->colision_Boss(map);
        if(!(aux == 0 && this->orientacion == 0 || aux == 1 && this->orientacion == 1)){
            this->move();
        }
        else{
            this->pos->setInicial();
            clock_posicion.restart();
        }
    }}
    
    if(actitud==1){
       
     if(detectada){
         this->getPosition()->setInicial();
          clock_posicion.restart();
        //if(this->clock_quieto.getElapsedTime().asSeconds() > 0.5){ this->quieto = false; }
        if(!rapido){ this->set_speed(fast); rapido = true;}
        int distancia = this->pos->getX() - s->getPosicion()->getX();
        if(distancia > 0){
            this->orientacion = 1; 
            this->attack2(s);
            //if(this->clock_quieto.getElapsedTime().asSeconds() > 0.1){ this->orientacion = 0; }
        }
        else{
            this->orientacion = 0; 
            this->attack2(s);
            //if(this->clock_quieto.getElapsedTime().asSeconds() > 0.1){ this->orientacion = 1; }
        }
        //this->move();
     }
    }
    
}
开发者ID:4nk1r4,项目名称:NewMetroid,代码行数:55,代码来源:Boss.cpp

示例5: do_motion

// ----------------------------------------------------------------------------
void do_motion (void)
{
	static GLint prev_time = 0;

	//int time = glutGet(GLUT_ELAPSED_TIME);
	int time=theClock.getElapsedTime().asMilliseconds();
	angle += (time-prev_time)*0.1;
	prev_time = time;

	//glutPostRedisplay ();
}
开发者ID:kenpower,项目名称:Assimp,代码行数:12,代码来源:OpenGLLoader.cpp

示例6: playerControl

void Engine::playerControl(Player *player, float &delta_time, bool pressed)
{
    sf::Vector2f vectors;
    static sf::Vector2f wektor;
    static sf::Clock clockCrash;
    static sf::Time timerCrash;

    if(player->lifes < -1)
    {
        game_over.setString(stringGameOver+toString(player->score));
        game_over.setPosition((windowSize.x-game_over.getGlobalBounds().width)/2, windowSize.y/2);
        gameOver = true;
    }

    if(crash)
    {
        player->ship.setOutlineColor(red);
        timerCrash = clockCrash.getElapsedTime();

        if(player->lifes >= 0)
            info.setString(stringInfo+toString(player->lifes));

        if(timerCrash >= sf::seconds(5))
        {
            crash = false;
            player->ship.setOutlineColor(cyan);
            clockCrash.restart();
            player->lifes -= 1;
        }
    }

    if(player->ship.getPosition().y < - 3.f)
        player->ship.setPosition(player->ship.getPosition().x, windowSize.y + 3.f);

    else if(player->ship.getPosition().y > windowSize.y + 3.f)
        player->ship.setPosition(player->ship.getPosition().x, - 3.f);

    else if(player->ship.getPosition().x > windowSize.x + 3.f)
        player->ship.setPosition(-3.f, player->ship.getPosition().y);

    else if(player->ship.getPosition().x < - 3.f)
        player->ship.setPosition(windowSize.x + 3.f, player->ship.getPosition().y);

    if(pressed)
    {
        wektor.x = std::sin((player->ship.getRotation()*M_PI) / 180.0f);
        wektor.y = -std::cos((player->ship.getRotation()*M_PI) / 180.0f);
    }

    vectors.x = wektor.x * player->velocity * delta_time;
    vectors.y = wektor.y * player->velocity * delta_time;

    player->ship.move(vectors);
}
开发者ID:mrtycjan,项目名称:Geometry-Techno-Meteor-Storm,代码行数:54,代码来源:Engine.cpp

示例7: main

int main(){
    sf::RenderWindow window(sf::VideoMode(800, 600), "New Metroid: Disparos");
    window.setFramerateLimit(60);
    
    std::vector<sf::Texture*> texturas;
    std::list<Bullet*> clip;
    std::list<Bullet*> toRemove;
    
    inicializar(texturas);
    float tempo;
    
    while(window.isOpen()){
        if(reloj.getElapsedTime().asMilliseconds() > UPDATE_TICK_TIME){
            tempo = reloj.getElapsedTime().asSeconds();
            reloj.restart();
            update(window, toRemove, clip, texturas);
        }
        render(window, toRemove, clip);
    }    
    return 0;
}
开发者ID:4nk1r4,项目名称:NewMetroid,代码行数:21,代码来源:Main.cpp

示例8: filterCollisions

	void filterCollisions(std::vector<anax::Entity>& entities) {
		sf::Time currentTime = m_clock.getElapsedTime();
		for (auto entity : entities) {
			if (entity.isValid() &&  entity.hasComponent<IgnoreCollisionComponent>()) {
				auto& ignoreCollisionComp = entity.getComponent<IgnoreCollisionComponent>();
				if(ignoreCollisionComp.reason == IgnoreCollisionReason::NEW_SPLIT_BODY){
					if (currentTime - ignoreCollisionComp.timeIgnoreCollisionAdded >= m_maxIgnoreTime) {
						entity.removeComponent<IgnoreCollisionComponent>();
						//std::cout << "about to mark as deleted" << std::endl;
					}
				}
			}
		}
	}
开发者ID:SundeepK,项目名称:Clone,代码行数:14,代码来源:FilterCollisionsSystem.cpp

示例9: updateGhosts

void Car::updateGhosts() {
    static sf::Clock clock = sf::Clock();
    
    sf::Time time = clock.getElapsedTime();
    
    sf::Vector2f lastLocation = this->mLastLocation;
    if (this->mCarGhostDrawables.size() > 0) {
        lastLocation = this->mCarGhostDrawables.back().ghost.getPosition();
    }
    
    // add new ghost
    float ghostDistance = length(this->mCurrentLocation - lastLocation);
    if (ghostDistance >= Car::MAX_GHOSTS_DISTANCE && this->mVelocity > 0.0f) {
        sf::RectangleShape ghost(sf::Vector2f(Car::CAR_WIDTH, Car::CAR_HEIGHT));
        ghost.setOrigin(Car::CAR_WIDTH / 2.0f, Car::CAR_HEIGHT / 2.0f);
        
        sf::Vector2f dir = normalize(this->mCurrentDirection);
        ghost.setPosition(this->mCurrentLocation); // - (dir * (Car::MAX_GHOSTS_DISTANCE + 20.0f)));
        ghost.setRotation(RAD_TO_DEG(heading(dir)));
        
        ghost.setFillColor(this->mCarDrawable.getFillColor());
        
        this->mCarGhostDrawables.push_back(Ghost(ghost, time.asMilliseconds()));
        
        if (this->mCarGhostDrawables.size() >= Car::MAX_GHOSTS) {
            this->mCarGhostDrawables.erase(this->mCarGhostDrawables.begin());
        }
    }
    
    // do we need to remove some ghosts?
    std::list<Ghost>::iterator it = this->mCarGhostDrawables.begin();
    while (it != this->mCarGhostDrawables.end()) {
        if ((time.asMilliseconds() - (*it).age) >= Car::MAX_GHOSTS_AGE) {
            it = this->mCarGhostDrawables.erase(it);
        } else {
            ++it;
        }
    }
       
    // adjust alphas
    int i = this->mCarGhostDrawables.size()+1;
    //float steps = (80.0f - (80.0f * (MAX_VELOCITY / this->mVelocity))) / static_cast<float>(i);
    float steps = 80.0f / static_cast<float>(i);
    sf::Color color = this->mCarDrawable.getFillColor();
    for (std::list<Ghost>::reverse_iterator it = this->mCarGhostDrawables.rbegin(); it != this->mCarGhostDrawables.rend(); ++it) {
        color.a = steps * i--;
        (*it).ghost.setFillColor(color);
    }

}
开发者ID:JannesMeyer,项目名称:rac0r,代码行数:50,代码来源:Car.cpp

示例10: interactTastatura

std::string Comunicare :: interactTastatura(sf::RenderWindow &fereastra, sf::Event &ev)
{
    static sf::Clock timpActiune;
    float timpRamas = timpActiune.getElapsedTime().asSeconds();
    if(ev.type == sf::Event::TextEntered)
        text_dl_tastatura += (char)ev.text.unicode;
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Return))
        if(timpRamas > 0.1)
        {
            timpActiune.restart();
            text_dl_tastatura += '\n';
        }
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::BackSpace) && !text_dl_tastatura.empty())
        text_dl_tastatura.erase(text_dl_tastatura.size()-1,1);
}
开发者ID:Gocware,项目名称:Spanzuratoare,代码行数:15,代码来源:Comunicare.cpp

示例11: framesPerSecond

float framesPerSecond(sf::Clock & clock) {
    frames_count++;
    if (frames_count >= MAX_FRAME_SAMPLES) {
        fps = ((float)frames_count / (float)clock.getElapsedTime().asMilliseconds()) * 1000;
        clock.restart();
        frames_count = 0;
    }
    //if (clock.getElapsedTime().asMilliseconds() >= 1000) {
    //    clock.restart();
    //    fps = count;
    //    count = 0;
    //}
    fflush(stdout);
    return fps;
}
开发者ID:satanas,项目名称:sfml-test,代码行数:15,代码来源:main.cpp

示例12: step

    float step()
    {
        ++mySteps;

        float time(myClock.getElapsedTime().asSeconds());

        if (time >= 1.f)
        {
            std::ostringstream str; str.precision(4);
            str<<mySteps/time;
            setString(str.str());
            mySteps = 0;
            myClock.restart();
        }
        return time;
    }
开发者ID:posva,项目名称:InputManager,代码行数:16,代码来源:FPS.hpp

示例13: LoadingBubbles

void PlayScene::LoadingBubbles(sf::Clock const& clock)
{
    const uint32 ms = clock.getElapsedTime().asMilliseconds();

    // Create obstacle bubbles (Todo factory)
    if (ms - m_bubbleLoadTimer >= 2000)
    {
        const uint16 bubbleRadius = ObstacleBubbleDefault::Size / 2;
        const uint16 obstacleCount
            = PlaySceneDefault::GoodBubbleCount + PlaySceneDefault::BadBubbleCount;

        sf::Vector2u const& winSize = sGame->GetWindow()->getSize();
        const uint16 maxBubbleCoordCount = winSize.x - (winSize.x - winSize.y);
        const float forBubbleSize = ObstacleBubbleDefault::Size;

        // Fill coords
        std::vector<sf::Vector2f> bubbleCoords;
        for (uint16 i = 0; i < maxBubbleCoordCount / forBubbleSize; ++i)
            bubbleCoords.push_back(sf::Vector2f(i * forBubbleSize, i * forBubbleSize));

        if (bubbleCoords.size() < obstacleCount)
            Assert(true, FS("PlayScene::LoadingBubbles: Need to generate more coordinates! "
            "Generated coords '%%%' < need count '%%%'.", bubbleCoords.size(), obstacleCount));

        // Shuffle
        std::random_shuffle(bubbleCoords.begin(), bubbleCoords.end());

        // Creating...
        for (uint16 i = 0; i < obstacleCount; ++i)
        {
            ObstacleBubble* obstacle = nullptr;
            eMoveDirs dir = RandI<uint16>(0, 1) ? eMoveDirs::Right : eMoveDirs::Left;

            // Create good bubbles
            if (i < PlaySceneDefault::GoodBubbleCount)
                obstacle = new GoodBubble(bubbleRadius, bubbleCoords.at(i), dir);
            // Create bad bubbles
            else
                obstacle = new BadBubble(bubbleRadius, bubbleCoords.at(i), dir);

            m_bubbles.push_back(obstacle);
        }

        m_bubbleLoaded = true;
    }
}
开发者ID:rescr1pt,项目名称:simplebubble,代码行数:46,代码来源:PlayScene.cpp

示例14: if

void	AMovingObject::move(const sf::Clock &clock)
{
	float	dist;

	dist = clock.getElapsedTime().asMicroseconds() * speed;
	if (direction % 2 == 1)
		dist /= 1.4f;
	if (direction >= 7)
		posY -= dist;
	else if (direction <= 3)
		posY += dist;
	if (direction % 3 == 0)
		posX += dist;
	if (direction % 3 == 1)
		posX -= dist;
	posX = (posX < 0) ? 0 : (posX >= WIDTH) ? WIDTH - 1 : posX;
	posY = (posY < 0) ? 0 : (posY >= LENGTH) ? LENGTH - 1 : posY;
}
开发者ID:smootise,项目名称:R-Type,代码行数:18,代码来源:AMovingObject.cpp

示例15: DoLogic

void MenuBackground::DoLogic()
{
    //Now the background of menu will move always at the same pace
    static sf::Clock frameTime;
    m_view.move(1.2f*frameTime.getElapsedTime().asMilliseconds(),0);
    frameTime.restart();

    //When the view reaches the End of the current level, reset the view and Load a new level
    if(m_view.getCenter().x >= m_tileSize.x * m_levelLength)
    {
        m_view = m_window.getView();

        m_view.setCenter(400,225);

        m_renderTex.setView(m_view);
        Init();
    }

    m_renderTex.setView(m_view);
}
开发者ID:abodelot,项目名称:Kroniax,代码行数:20,代码来源:MenuBackground.cpp


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