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


C++ Time::asMicroseconds方法代码示例

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


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

示例1: update

void Engine::update(sf::Time dt)
{
	m_entMgr->update(dt.asMicroseconds());
	
	if(Stats::get()->getLives() < 0) m_exit = true;
	m_dbg->update(dt.asMilliseconds(), m_entMgr->getPlayer()->getPos());
}
开发者ID:Fedake,项目名称:Pacman,代码行数:7,代码来源:Engine.cpp

示例2: update

 template <typename Game> void update(const sf::Time & elapsedTime, Game *) {
     timer += elapsedTime.asMicroseconds();
     glowFadeTimer += elapsedTime.asMicroseconds();
     if (timer > 65000) {
         timer -= 65000;
         frameIndex++;
         if (frameIndex > 5) {
             frameIndex = 5;
             killFlag = true;
         }
     }
     uint8_t color =
         Easing::easeOut<2>(glowFadeTimer, static_cast<int64_t>(300000)) *
         230;
     glow.setColor(sf::Color(color, color, color, 255));
 }
开发者ID:evanbowman,项目名称:Blind-Jump,代码行数:16,代码来源:smallExplosion.hpp

示例3: update

 template <typename Game> void update(const sf::Time & elapsedTime, Game *) {
     timer += elapsedTime.asMicroseconds();
     glowFadeTimer += elapsedTime.asMicroseconds();
     static const int frameTransitionTime = 70000;
     if (timer > frameTransitionTime) {
         timer -= frameTransitionTime;
         frameIndex++;
         static const int maxFrame = 8;
         if (frameIndex > maxFrame) {
             frameIndex = maxFrame;
             killFlag = true;
         }
     }
     uint8_t color =
         Easing::easeOut<1>(glowFadeTimer, static_cast<int64_t>(560000)) *
         230;
     glow.setColor(sf::Color(color, color, color, 255));
 }
开发者ID:evanbowman,项目名称:Blind-Jump,代码行数:18,代码来源:FireExplosion.hpp

示例4: playSong

/**
 * advance the song by the given delta time
 * and play/stop the notes according to the events
 * present in that delta time
 */
static void playSong(
    linthesia::Context &context,
    const sf::Time& delta
) {
    auto events =context.update(delta.asMicroseconds());
    for (const auto& oneEvent : events) {
        context.midiOut.write(oneEvent.second);
    }
}
开发者ID:EQ4,项目名称:linthesia,代码行数:14,代码来源:select_midi_out.cpp

示例5: updateAnimation

void AnimHandler::updateAnimation(const sf::Time& time_elapsed)//Update the current frame (must be called at least once before draw()!)
{
	ctime += (int)time_elapsed.asMicroseconds();
	if (ctime < currentFrame->delay) return;
	cframe++;
	if (cframe >= (int)currentAnim->frames.size() || cframe < 0)
	{
		cframe = 0;
	}
	ctime = ctime % currentFrame->delay;
	currentFrame = &currentAnim->frames[cframe];
}
开发者ID:Gatleos,项目名称:hexmap,代码行数:12,代码来源:AnimHandler.cpp

示例6: target

SoundManager::FadedMusic::FadedMusic(
    VFileMusic& music, float target, sf::Time fadeDuration):
    target(target),
    music(&music),
    increment(0)
{
    if (fadeDuration.asMicroseconds()) {
        music.setVolume(100 - target);
        increment = (target - music.getVolume()) / fadeDuration.asSeconds();
    } else {
        music.setVolume(target);
    }
}
开发者ID:Oberon00,项目名称:jd,代码行数:13,代码来源:SoundManager.cpp

示例7: drawFpsCounter

	void drawFpsCounter(sf::RenderWindow& aWindow, const sf::Font& aFont, sf::Time aDeltaTime)
	{
		sf::Text text;
		text.setFont(aFont);
		text.setColor(sf::Color::Red);
		text.setPosition(0, 50.0f);

		char buffer[Int64TextWidth];
		_i64toa_s(aDeltaTime.asMicroseconds(), buffer, Int64TextWidth, 10);
		//_gcvt_s(buffer, Int64TextWidth, elapsedTime, 20);

		text.setString(buffer);

		aWindow.draw(text);
	}
开发者ID:Spanky,项目名称:game-engine,代码行数:15,代码来源:GO_ComponentUpdater.cpp

示例8: main

int main(int argv, char* argc[])
{
	sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "SFML and Box2D", sf::Style::Close);

	window.setVerticalSyncEnabled(false); // vsync messes with updates

	b2Vec2 gravity(0.0f, 0.0f);

	b2World world(gravity);

	sf::Clock clock;
	sf::Clock seconds;

	while (window.isOpen())
	{
		sf::Time elapsed = clock.getElapsedTime();

		if (elapsed.asMicroseconds() >= updateRate.asMicroseconds())
		{
			clock.restart();
			update(&window);
		}
		elapsed = seconds.getElapsedTime();
		if (elapsed.asSeconds() >= 1)
		{
			UPS = tick;
			FPS = frame;
			std::cout << "UPS: " << UPS << ", FPS: " << FPS << std::endl;
			tick = 0;
			frame = 0;
			seconds.restart();
		}

		render(&window);
	}



	return 0;
}
开发者ID:SinisterSlothMinister,项目名称:SFML-2D-Game,代码行数:40,代码来源:main.cpp

示例9: Update_velocity

void Skier::Update_velocity( sf::Time elapsed_time ) {
  
    // This multiplier acts as a general physics speed modifier.
    // All other similar multiplying values behave as relative intensities
    // compared to other physics effects
    long double amount = elapsed_time.asMicroseconds() / 10000.0f;

    // increase lateral velocity by 'amount' if the right or left arrow key
    // is being pressed.  Decrease vertical (downward) velocity by amount
    // if the up arrow is pressed.

    if( sf::Keyboard::isKeyPressed( sf::Keyboard::Right ) ) {
        // turn right
        m_velocity += Util::Get_perpendicular_v2f( m_velocity, amount / 30.0f );
    } else if( sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) ) {
        // turn left.
        m_velocity -= Util::Get_perpendicular_v2f( m_velocity, amount / 30.0f );
    }
    if( sf::Keyboard::isKeyPressed( sf::Keyboard::Up ) ) {
        // slow down...
        m_velocity.y /= 1.0f + amount / 20.0f;
    
        // ... but not too much
        if( m_velocity.y < 0.0f ) {
            m_velocity.y = 0.0f;
        }
        // friction:
        m_velocity.x /= 1.0f + amount / 20.0f;
    }
    #if 0
    if( sf::Keyboard::isKeyPressed( sf::Keyboard::Down ) ) {
        // Nothing curently
    }
    #endif

    // gravity
    m_velocity.y += amount * 2 / 980.6f;

    Normalize_velocity();
}
开发者ID:ndeakin,项目名称:ski,代码行数:40,代码来源:skier.cpp

示例10: update

    void update(const sf::Time & elapsedTime, Game * pGame) {
        switch (state) {
        case State::opening:
            animationTimer += elapsedTime.asMicroseconds();
            if (animationTimer > 50000) {
                animationTimer -= 50000;
                frameIndex++;
                if (frameIndex > 5) {
                    frameIndex = 4;
                    state = State::ready;
                }
            }
            break;

        case State::ready:
            // TODO: play reward sound
            pGame->getUI().setPowerup(powerup);
            state = State::complete;
            break;

        default:
            break;
        }
    }
开发者ID:evanbowman,项目名称:Blind-Jump,代码行数:24,代码来源:treasureChest.hpp

示例11: update

void Crocodile::update(sf::Time elapsed_time) {

    sf::Vector2f previous_direction = direction;
    bool key_pressed = (new_direction != sf::Vector2f(0, 0));
    bool u_turn = (new_direction == - direction);
    bool already_doing_a_turn = (path.front().length < 0);
    if (key_pressed && ! u_turn && ! already_doing_a_turn) {
        direction = new_direction;
    }

    // If the direction has changed, add 2 new path chunks:
    // one for the curve (smooth turn) and one for the straight
    // line that follows.
    if (direction != previous_direction) {
        sf::Vector2f current_head_position = sprites.front().getPosition();

        PathChunk curve;
        curve.from = previous_direction;
        curve.to = direction;
        curve.length = M_PI * curve_radius / 2.0;
        curve.position = current_head_position;
        path.push_front(curve);

        PathChunk straight_line;
        straight_line.from = direction;
        straight_line.to = direction;
        straight_line.length = - curve.length;
        straight_line.position = current_head_position
                + direction*curve_radius
                + previous_direction*curve_radius;
        path.push_front(straight_line);
    }

    // update the distance-to-head of the first path chunk
    sf::Int64 elapsed_ms = elapsed_time.asMicroseconds();
    float velocity = elapsed_ms * speed;
    path.front().length += velocity;

    // update position of all sprites
    std::vector<sf::Sprite>::iterator sprite = sprites.begin();
    std::deque<PathChunk>::iterator chunk = path.begin();
    float chunk_dist_to_head = chunk->length;
    float sprite_dist_to_head = 0.0;

    while (true) {

        if (chunk_dist_to_head >= sprite_dist_to_head) {

            sf::Vector2f prev_pos = sprite->getPosition();

            // Compute new position depending on the type of the path chunk
            sf::Vector2f new_pos;
            // offset is the distance ran on the current path chunk
            float offset = chunk_dist_to_head - sprite_dist_to_head;

            if (chunk->from == chunk->to) { // straight line
                sf::Vector2f shifting = chunk->to * offset;
                new_pos = chunk->position + shifting;

            } else { // curve

                // theta is the angle travelled along on the current path chunk
                float theta = offset / curve_radius;

                float absolute_angle;

                if (chunk->from == sf::Vector2f(1.0, 0.0)
                        && chunk->to == sf::Vector2f(0.0, 1.0)) {
                    absolute_angle = - M_PI / 2.0 + theta;

                } else if (chunk->from == sf::Vector2f(1.0, 0.0)
                        && chunk->to == sf::Vector2f(0.0, -1.0)) {
                    absolute_angle = + M_PI / 2.0 - theta;

                } else if (chunk->from == sf::Vector2f(-1.0, 0.0)
                        && chunk->to == sf::Vector2f(0.0, 1.0)) {
                    absolute_angle = - M_PI / 2.0 - theta;

                } else if (chunk->from == sf::Vector2f(-1.0, 0.0)
                        && chunk->to == sf::Vector2f(0.0, -1.0)) {
                    absolute_angle = M_PI / 2.0 + theta;

                } else if (chunk->from == sf::Vector2f(0.0, 1.0)
                        && chunk->to == sf::Vector2f(1.0, 0.0)) {
                    absolute_angle = M_PI - theta;

                } else if (chunk->from == sf::Vector2f(0.0, 1.0)
                        && chunk->to == sf::Vector2f(-1.0, 0.0)) {
                    absolute_angle = + theta;

                } else if (chunk->from == sf::Vector2f(0.0, -1.0)
                        && chunk->to == sf::Vector2f(1.0, 0.0)) {
                    absolute_angle = M_PI + theta;

                } else if (chunk->from == sf::Vector2f(0.0, -1.0)
                        && chunk->to == sf::Vector2f(-1.0, 0.0)) {
                    absolute_angle = - theta;

                } else {
                    std::cout << "should not happen" << std::endl;
//.........这里部分代码省略.........
开发者ID:marmottine,项目名称:Crocodin,代码行数:101,代码来源:Crocodile.cpp

示例12: UpdateCurrent

void PlayerObject::UpdateCurrent(sf::Time p_xDtime){
	sf::Vector2f l_xVel((sf::Keyboard::isKeyPressed(sf::Keyboard::D) - sf::Keyboard::isKeyPressed(sf::Keyboard::A)), (sf::Keyboard::isKeyPressed(sf::Keyboard::S) - sf::Keyboard::isKeyPressed(sf::Keyboard::W)));
	
	setVelocity(l_xVel * (float)p_xDtime.asMicroseconds());
}
开发者ID:Waluario,项目名称:Suit_Em_Up,代码行数:5,代码来源:PlayerObject.cpp

示例13: update


//.........这里部分代码省略.........
                    angleFunction(target.x, target.y + 8, position.x,
                                  position.y));
                pGame->getSounds().play(ResHandler::Sound::silenced,
                                        this->shared_from_this(), 220.f, 5.f);
            }
        }
        if (timer > 300) {
            timer -= 300;
            shotCount = 0;
            state = State::pause;
        }
        break;

    case State::shootBegin:
        facePlayer();
        if (timer > 80) {
            timer -= 80;
            frameTimer = 0;
            target = player.getPosition();
            state = State::shooting;
            frameIndex = 4;
        }
        break;

    case State::dashBegin:
    begin:
        facePlayer();
        if (timer > 352) {
            timer -= 352;
            state = State::dashing;
            sounds.play(ResHandler::Sound::wooshMono, this->shared_from_this(),
                        220.f, 5.f);
            frameIndex = 2;
            uint8_t tries{0};
            float dir{static_cast<float>(rng::random<359>())};
            do {
                tries++;
                if (tries > 254) {
                    state = State::shootBegin;
                    frameIndex = 3;
                    goto begin;
                }
                dir += 12;
            } while (wallInPath(walls, dir, position.x, position.y));
            hSpeed = 5 * cos(dir);
            vSpeed = 5 * sin(dir);
            if (hSpeed > 0) {
                dasherSheet.setScale(-1, 1);
            } else {
                dasherSheet.setScale(1, 1);
                dasherSheet.setScale(1, 1);
            }
        }
        break;

    case State::dashing:
        frameTimer += elapsedTime.asMilliseconds();
        if (frameTimer > 40) {
            frameTimer = 0;
            blurEffects.emplace_back(dasherSheet.getSpritePtr(), position.x,
                                     position.y);
        }
        if (timer > 250) {
            timer -= 250;
            state = State::dashEnd;
            frameIndex = 1;
            hSpeed = 0.f;
            vSpeed = 0.f;
        }

        if (Enemy::checkWallCollision(walls, position.x, position.y)) {
            hSpeed *= -1.f;
            vSpeed *= -1.f;
        }
        break;

    case State::dashEnd:
        if (timer > 150) {
            blurEffects.clear();
            timer -= 150;
            state = State::idle;
            frameIndex = 0;
        }
        break;
    }

    if (!blurEffects.empty()) {
        for (auto it = blurEffects.begin(); it != blurEffects.end();) {
            if (it->getKillFlag())
                it = blurEffects.erase(it);
            else {
                it->update(elapsedTime);
                ++it;
            }
        }
    }

    position.x += hSpeed * (elapsedTime.asMicroseconds() * 0.00005f);
    position.y += vSpeed * (elapsedTime.asMicroseconds() * 0.00005f);
}
开发者ID:evanbowman,项目名称:Blind-Jump,代码行数:101,代码来源:dasher.cpp

示例14: getFPS

float Game::getFPS(const sf::Time& time) {
	return (1000000.0f / time.asMicroseconds());
}
开发者ID:madnotdead,项目名称:GrottoEscape,代码行数:3,代码来源:Game.cpp

示例15: main


//.........这里部分代码省略.........

	sf::RectangleShape _bounding2(sf::Vector2f(_enemy.getBoundingBox().width - 1, _enemy.getBoundingBox().height - 1));
	_bounding2.setPosition(_enemy.getPosition());
	_bounding2.setFillColor(sf::Color::Transparent);
	_bounding2.setOutlineColor(sf::Color::Red);
	_bounding2.setOutlineThickness(1);

	sf::Font font;
	font.loadFromFile("VeraMono.ttf");
	sf::Text _text("Debug", font, 12);
	_text.setPosition(0, 0);

	sf::Clock clock;
	sf::Time timeSinceLastUpdate = sf::Time::Zero;

	// Start the game loop
	while (window.isOpen())
	{
		sf::Time elapsedTime = clock.restart();
		timeSinceLastUpdate += elapsedTime;

		while (timeSinceLastUpdate > TimePerFrame)
		{
			timeSinceLastUpdate -= TimePerFrame;

			// Process events
			sf::Event event;
			while (window.pollEvent(event))
			{
				// Close window : exit
				if (event.type == sf::Event::Closed)
					window.close();

				if(event.type == sf::Event::KeyPressed)
				{
					short id = 1;
					for( auto& i : _gameObjects )
					{
						i->update(event, id);
						id++;
					}
				}
			}

			if(checkCollisions(_gameObjects, _texts))
				_texts["Collision"] = "Detected";
			else
				_texts["Collision"] = "NOT Detected";

			std::map<std::string, std::string>::iterator i = _texts.begin();
			std::stringstream ss;

			for( ; i != _texts.end(); ++i )
			{
				ss << i->first << ": " << i->second << std::endl << std::endl;
			}

			_text.setString(ss.str());
		}

		_bounding1.setPosition(_player.getPosition());
		_bounding2.setPosition(_enemy.getPosition());

		_statisticsUpdateTime += elapsedTime;
		_statisticsNumFrames += 1;

		if (_statisticsUpdateTime >= sf::seconds(1.0f))
		{
			std::stringstream fps, timeupdate;
			fps << _statisticsNumFrames;
			timeupdate << _statisticsUpdateTime.asMicroseconds() / _statisticsNumFrames;

			_statisticsUpdateTime -= sf::seconds(1.0f);
			_statisticsNumFrames = 0;

			_texts["FPS"] = fps.str() + "\n" + "Time / Update = " + timeupdate.str() + "us";
		}

		window.clear();

		window.draw(_background);
		// window.draw(m_vertices, &m_tileset);
		window.draw(_cliffsBottom);
		window.draw(_cliffsTop);
		window.draw(_platform);
		window.draw(_platformBottom);

		for( auto& i : _gameObjects )
		{
			window.draw(*i);
		}

		window.draw(_text);

		window.draw(_bounding1);
		window.draw(_bounding2);

		window.display();
	}
}
开发者ID:koniin,项目名称:CollisionTest,代码行数:101,代码来源:Main.cpp


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