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


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

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


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

示例1: Move

void Platform::Move(sf::Time &deltaTime)
{
	//find the correct bools
	if(m_left > m_posMaxFinal)
		m_isMovingLeft = true;
	else
	{
		m_isMovingLeft = false;
		m_posMaxFinal = m_posMaxTwo;
	}

	if((m_right - m_size.x) < m_posMaxFinal)
		m_isMovingRight = true;
	else
	{
		m_isMovingRight = false;
		m_posMaxFinal = m_posMaxOne;
	}

	//turn bools into floats
	if(m_isMovingLeft)
		m_movement.x -= m_movSpeedAddition * deltaTime.asMilliseconds();
	if(m_isMovingRight)
		m_movement.x += m_movSpeedAddition * deltaTime.asMilliseconds();

	//don't go over max
	if(m_movement.x >= m_movSpeedMax)
		m_movement.x = m_movSpeedMax;
	if(m_movement.x <= -m_movSpeedMax)
		m_movement.x = -m_movSpeedMax;

	m_rect.move(m_movement);
	m_sprite.move(m_movement);
}
开发者ID:Nicholas-Swift,项目名称:Game-of-Crates,代码行数:34,代码来源:Platform.cpp

示例2: update

void Pad::update(sf::Time delta)
{
    pad.move(movement.x * delta.asMilliseconds(), movement.y * delta.asMilliseconds());

    float x = pad.getPosition().x;
    float y = pad.getPosition().y;

    if(x < boundOrigin.x)
    {
        pad.setPosition(boundOrigin.x,y);
    }
    if(x + size.x > boundOrigin.x + boundArea.x)
    {
        pad.setPosition(boundOrigin.x + boundArea.x - size.x,y);
    }
    if(y < boundOrigin.y)
    {
        pad.setPosition(x,boundOrigin.y);
    }
    if(y + size.y > boundOrigin.y + boundArea.y)
    {
        pad.setPosition(x,boundOrigin.y + boundArea.y - size.y);
    }

}
开发者ID:Pinkii-,项目名称:PONGplus,代码行数:25,代码来源:pad.cpp

示例3: 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

示例4: update

void Map::update(const sf::Time& elapsed_time, uint score)
{
  // How many pixels of moving
  float move = elapsed_time.asMilliseconds() * _speed;

  // Move backgrounds
  for(sf::Sprite& background : _backgrounds)
  {
    background.move(-move, 0);
    if(background.getPosition().x < -_width )
      background.move(_width * 2, 0);
  }

  // Move clouds
  for( sf::Sprite& cloud : _clouds )
  {
    cloud.move(-move, 0);
    if(cloud.getPosition().x < -cloud.getGlobalBounds().width)
      positionCloud(cloud, _width);
  }

  // Move bird
  if( score > _bird_score_limit )
  {
     _bird.move(-move * _bird_speed_modificator, 0);

     // Bird goes out of screen, randomly re-place it
     const static float bird_screen_limit = - _bird.getGlobalBounds().width;
     if( _bird.getPosition().x < bird_screen_limit )
       placeBird();
  }
  std::cout << _bird.getPosition().x << std::endl;
  // Take care of trees (move and generate)
  updateTrees(move, score);
}
开发者ID:bdajeje,项目名称:chrome-easter-game,代码行数:35,代码来源:map.cpp

示例5: Animate

void Player::Animate(sf::Time &deltaTime)
{
    if(m_isMovingRight || m_isMovingLeft)
    {
        frameCounter += frameSpeed * deltaTime.asMilliseconds() * 0.001;
        if(frameCounter >= switchFrame)
        {
            frameCounter = 0;
            source.x++;
            if(source.x * 32 >= 32*3)
                source.x = 0;
        }
    }

    if(m_isMovingRight)
        source.y = 2; //source corresponds with .png
    else if(m_isMovingLeft)
        source.y = 1;
    else if(m_onGround)
    {
        source.y = 0;
        source.x = 1;
    }
    else if(!m_onGround)
    {
        //source.y = 3; Take out the looking back while falling: Quality of life change for CHRIS ZITNIK - WHAT A GUY
        source.y = 0;
        source.x = 1;
    }

    m_sprite.setTextureRect(sf::IntRect(source.x * 32, source.y * 32, 32, 32)); //make sure that texture is 32!!
}
开发者ID:Nicholas-Swift,项目名称:Game-of-Crates,代码行数:32,代码来源:Player.cpp

示例6: update

/// Update the current game state 
void Application::update()
{
    const sf::Time elapsedTime = clock_.restart();
    
    if(currentState_)
        currentState_->update(elapsedTime.asMilliseconds());
    
    uiCtx_->Update();      
}
开发者ID:okard,项目名称:spaceg,代码行数:10,代码来源:Application.cpp

示例7: draw

    virtual void draw(sf::Time deltaTime) {
        float tedeuszWajhePrzeusz=200;
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
            vel.x-=50;
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
            vel.x+=50;
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
            vel.y-=50;
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
            vel.y+=50;

        float l = std::min(500.0f, Utils::vecLength(vel));
        Utils::normalize(vel);
        vel*=l;

        aspPlayer.move(vel.x*deltaTime.asSeconds(), vel.y*deltaTime.asSeconds());
        aspPlayer.update(l*deltaTime.asMilliseconds()/100.0f);
        vel*=0.9f;
        if (vel.x<0 && aspPlayer.getAnim()!=&aLeft)
            aspPlayer.setAnimation(&aLeft);

        if (vel.x>0 && aspPlayer.getAnim()!=&aRight)
            aspPlayer.setAnimation(&aRight);

        for(int i = 0; i < vecLvlData.size(); i++){
            if(Collision::PixelPerfectTest(vecLvlData[i].sprite, aspPlayer)){
                sceneManager->setActiveScene(vecLvlData[i].nginName);
            }
        }

        window->clear();
        backgroundSprite.setScale(
            window->getSize().x / backgroundSprite.getLocalBounds().width,
            window->getSize().y / backgroundSprite.getLocalBounds().height);
        window->draw(backgroundSprite);
        window->draw(logoSprite);

        for(int i = 0; i < vecLvlData.size(); i++){
            window->draw(vecLvlData[i].sprite);
            sf::Text description = sf::Text(vecLvlData[i].name, Common::Font::Comic_Sans);
            description.setScale(0.7, 0.7);
            description.setPosition(vecLvlData[i].sprite.getGlobalBounds().left + vecLvlData[i].sprite.getGlobalBounds().width/2.0 - description.getGlobalBounds().width/2.0,
                                    vecLvlData[i].sprite.getGlobalBounds().top+vecLvlData[i].sprite.getGlobalBounds().height);
            if(!sceneManager->scenes[vecLvlData[i].nginName]->isLocked()){
                description.setColor(sf::Color(0.0, 255.0, 0.0, 255.0));
            }
            else{
                description.setColor(sf::Color(52.0, 25.0, 255.0, 255.0));
            }
            window->draw(description);
            if (Utils::isMouseOnSprite(vecLvlData[i].sprite, window) && sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
                sceneManager->setActiveScene(vecLvlData[i].nginName);
            }
        }
        window->draw(aspPlayer);
    }
开发者ID:StylishTriangles,项目名称:TadzikEngine,代码行数:56,代码来源:Launcher.hpp

示例8: onSeek

    void NSFSoundStream::onSeek(sf::Time timeOffset) {
        sf::Lock lock(mutex);

        if(!activeSamplers.empty()) {
            auto & sampler = activeSamplers.front();
            auto & emu = sampler.first;

            handleError(emu->seek(static_cast<long>(timeOffset.asMilliseconds())));
        }
    }
开发者ID:jatemack,项目名称:hikari,代码行数:10,代码来源:NSFSoundStream.cpp

示例9: updateSpeed

void Player::updateSpeed(const sf::Time& elapsed_time)
{
    // Update speed
    if( isMoving() )
    {
        if(isMaxSpeedReached())
            return;

        // Speed gain depending on elapsed time
        float speed_gain = elapsed_time.asMilliseconds() * _acceleration;

        // Moving to left means minus speed
        if( _moving_to_direction == Direction::Left )
            speed_gain = -speed_gain;

        // Update speed
        _horizontal_speed += speed_gain;

        // Respect max speed
        if( std::abs(_horizontal_speed) > _max_speed )
            _horizontal_speed = ( _moving_to_direction == Direction::Left ) ? -_max_speed : _max_speed;
    }
    // Not moving, but remaining inertia
    else if( _horizontal_speed != 0.f )
    {
        // Speed loss depending on elapsed time
        float speed_loss = elapsed_time.asMilliseconds() * _deceleration;

        if( _horizontal_speed > 0.f )
        {
            _horizontal_speed -= speed_loss;
            if(_horizontal_speed < 0.f)
                _horizontal_speed = 0.f;
        }
        else if( _horizontal_speed < 0.f )
        {
            _horizontal_speed += speed_loss;
            if(_horizontal_speed > 0.f)
                _horizontal_speed = 0.f;
        }
    }
}
开发者ID:bdajeje,项目名称:Mario,代码行数:42,代码来源:player.cpp

示例10: update

 template <typename Game> void update(const sf::Time & elapsedTime, Game *) {
     timer += elapsedTime.asMilliseconds();
     if (timer > 50) {
         timer -= 50;
         frameIndex += 1;
         if (frameIndex == 4) {
             frameIndex = 3;
             killFlag = true;
         }
     }
 }
开发者ID:evanbowman,项目名称:Blind-Jump,代码行数:11,代码来源:shotPuff.hpp

示例11: tick

//Timer to keep track of the critter's status
void Critter::tick(sf::Time pausedTime) {
	//The time when the game is not paused. pausedTime is used to keep track of the time when the game is paused.
	long elapsedTime = critterClock.getElapsedTime().asMilliseconds() - pausedTime.asMilliseconds();

	//Determining the critter's status
	if (elapsedTime >= statusTime) {
		critterStatus = CritterStatus::NORMAL;
	} else if (critterStatus != CritterStatus::NORMAL && elapsedTime % 500 == 0) {
		//Critter is burned
		setHP(HP - 5);
	}
}
开发者ID:h-alchalabi,项目名称:Tower-Def,代码行数:13,代码来源:Critter.cpp

示例12: updateColor

void Enemy::updateColor(const sf::Time & elapsedTime) {
    if (colored) {
        colorTimer += elapsedTime.asMilliseconds();
        if (colorTimer > 20.f) {
            colorTimer -= 20.f;
            colorAmount -= 0.1f;
        }
    }

    if (colorAmount <= 0.f) {
        colored = false;
    }
}
开发者ID:evanbowman,项目名称:Blind-Jump,代码行数:13,代码来源:enemy.cpp

示例13:

void Dasher::Blur::update(const sf::Time & elapsedTime) {
    timer += elapsedTime.asMilliseconds();
    if (timer > 18) {
        timer = 0;
        sf::Color c = spr.getColor();
        if (c.a > 30) {
            c.a -= 30;
            spr.setColor(c);
        } else {
            killflag = true;
        }
    }
}
开发者ID:evanbowman,项目名称:Blind-Jump,代码行数:13,代码来源:dasher.cpp

示例14: vibrate

// NDK/JNI sub example - call Java code from native code
int vibrate(sf::Time duration)
{
    // First we'll need the native activity handle
    ANativeActivity *activity = sf::getNativeActivity();
    
    // Retrieve the JVM and JNI environment
    JavaVM* vm = activity->vm;
    JNIEnv* env = activity->env;

    // First, attach this thread to the main thread
    JavaVMAttachArgs attachargs;
    attachargs.version = JNI_VERSION_1_6;
    attachargs.name = "NativeThread";
    attachargs.group = NULL;
    jint res = vm->AttachCurrentThread(&env, &attachargs);

    if (res == JNI_ERR)
        return EXIT_FAILURE;

    // Retrieve class information
    jclass natact = env->FindClass("android/app/NativeActivity");
    jclass context = env->FindClass("android/content/Context");
    
    // Get the value of a constant
    jfieldID fid = env->GetStaticFieldID(context, "VIBRATOR_SERVICE", "Ljava/lang/String;");
    jobject svcstr = env->GetStaticObjectField(context, fid);
    
    // Get the method 'getSystemService' and call it
    jmethodID getss = env->GetMethodID(natact, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
    jobject vib_obj = env->CallObjectMethod(activity->clazz, getss, svcstr);
    
    // Get the object's class and retrieve the member name
    jclass vib_cls = env->GetObjectClass(vib_obj);
    jmethodID vibrate = env->GetMethodID(vib_cls, "vibrate", "(J)V"); 
    
    // Determine the timeframe
    jlong length = duration.asMilliseconds();
    
    // Bzzz!
    env->CallVoidMethod(vib_obj, vibrate, length);

    // Free references
    env->DeleteLocalRef(vib_obj);
    env->DeleteLocalRef(vib_cls);
    env->DeleteLocalRef(svcstr);
    env->DeleteLocalRef(context);
    env->DeleteLocalRef(natact);
    
    // Detach thread again
    vm->DetachCurrentThread();
}
开发者ID:binary1248,项目名称:SFML,代码行数:52,代码来源:main.cpp

示例15: update

	void GraphicsSystem::update( Engine& engine, World& world, SaveManager& saveManager, const sf::Time& frameTime )
	{
		r_renderWindow->setActive( true );

		engine.renderWindow.setTitle( m_configValues.window_name +
									  " " +
									  to_string( frameTime.asMilliseconds() ) +
									  " | EntityCount: " +
									  to_string( world.getEntityCount() ) );

		drawFunction();

		return;
	}
开发者ID:Maxomann,项目名称:kgEngine-2.0,代码行数:14,代码来源:GraphicsSystem.cpp


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