示例#1
0
	void AnimationController::Update()
	{
		PROFILE_SCOPED();
		const Uint32 now = SDL_GetTicks();

		for (auto i = m_animations.begin(); i != m_animations.end();) {
			Animation *animation = (*i).first.Get();
			Uint32 start = (*i).second;

			float remaining = 0.0f;
			if (!animation->IsCompleted())
				remaining = animation->Update(float(now - start) / 1000.f);

			if (animation->IsCompleted()) {
				Animation *nextAnimation = animation->GetNext();
				if (nextAnimation) {
					assert(!animation->IsRunning());
					m_animations.push_back(std::make_pair(RefCountedPtr<Animation>(nextAnimation), now - Uint32(-remaining * 1000.0f)));
					nextAnimation->Running();
				}
				m_animations.erase(i++);
			} else
				++i;
		}
	}
示例#2
0
	void Entity::Update(float dt)
	{
		
		Animation *animation = mAnimations[mCurrAnimation];
		animation->Update(dt);

	}
void GameObject::VUpdate(float dt)
{
    if(HasAnimations()) {
        Animation* animation = m_animations[m_currentAnimation];
        animation->Update(dt);
    }
}
示例#4
0
文件: tilemap.cpp 项目: pmprog/0Wave
void TileMap::Update()
{
	if( tileAnimations.size() > 0 )
	{
		for( std::vector<Animation*>::const_iterator i = tileAnimations.begin(); i != tileAnimations.end(); i++ )
		{
			Animation* a = (Animation*)(*i);
			a->Update();
		}
	}
}
示例#5
0
void Application::Update(float deltaTime) {
    try {
        //Check for lost device
        HRESULT coop = g_pDevice->TestCooperativeLevel();

        if (coop != D3D_OK) {
            if (coop == D3DERR_DEVICELOST) {
                if (m_deviceLost == false)
                    DeviceLost();
            }
            else if (coop == D3DERR_DEVICENOTRESET) {
                if (m_deviceLost == true)
                    DeviceGained();
            }

            Sleep(100);
            return;
        }

        m_animation.Update(deltaTime);

        //Keyboard input
        if (KeyDown(VK_ESCAPE)) {
            Quit();
        }

        if (KeyDown(VK_RETURN) && KeyDown(18)) {     //ALT + RETURN
            //Switch between windowed mode and fullscreen mode
            m_present.Windowed = !m_present.Windowed;

            DeviceLost();
            DeviceGained();

            if (m_present.Windowed) {
                RECT rc = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
                AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false);
                SetWindowPos(m_mainWindow, HWND_NOTOPMOST, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW);
                UpdateWindow(m_mainWindow);
            }
        }
    }
    catch(...) {
        g_debug << "Error in Application::Update() \n";
    }
}
void DialogCharacter::Update(int delta, string &emotionId, bool finishOneTimeEmotions, bool isInBackground)
{
    if (emotionId.length() == 0)
    {
        emotionId = defaultEmotionId;
    }

    if (characterOneTimeEmotions.count(emotionId) > 0)
    {
        OneTimeEmotion *pOneTimeEmotion = characterOneTimeEmotions[emotionId];

        Video *pVideo = pOneTimeEmotion->GetVideo();

        if (finishOneTimeEmotions)
        {
            pVideo->Finish();
        }
        else
        {
            pVideo->Update(delta);
        }

        if (pVideo->IsFinished() && pOneTimeEmotion->GetTransitionToEmotion().length() > 0)
        {
            pVideo->Reset();
            emotionId = pOneTimeEmotion->GetTransitionToEmotion();
        }
        else
        {
            return;
        }
    }

    vector<Animation *> *pForegroundLayers = GetForegroundLayersForEmotion(emotionId);

    if (pForegroundLayers != NULL)
    {
        for (unsigned int i = 0; i < pForegroundLayers->size(); i++)
        {
            Animation *pAnimation = (*pForegroundLayers)[i];
            pAnimation->Update(delta);
        }
    }

    // If this emotion is currently in the background (e.g., if the character is currently zoomed),
    // then we won't bother updating the eye frame duration list.
    if (isInBackground || characterEmotionEyeSpriteIds.count(emotionId) == 0)
    {
        return;
    }

    if (eyeFrameDurationList.size() == 0 || eyeFrameDurationList.size() != characterEmotionEyeSpriteIds[emotionId].size())
    {
        PopulateEyeFrameDurationList(emotionId);
    }

    msElapsedCurrentEyeFrame += delta;

    while (msElapsedCurrentEyeFrame > eyeFrameDurationList[currentEyeFrame])
    {
        msElapsedCurrentEyeFrame -= eyeFrameDurationList[currentEyeFrame];
        currentEyeFrame++;

        // If we've reached the end, then we'll wrap back around and get a
        // new random number representing the time until the next eye blink.
        if (currentEyeFrame >= eyeFrameDurationList.size())
        {
            currentEyeFrame = 0;
            eyeFrameDurationList[0] = (int)(rand() % 2001) + 2000;
        }
    }
}