示例#1
0
void Animation::Update(float32 timeElapsed)
{
	if (state & STATE_IN_PROGRESS)
	{
	    if (state & STATE_PAUSED)
	        return;
	    
		if (state & STATE_REVERSE)
		{
			time += timeElapsed*timeMultiplier;
			
			float halfTimeLength = 0.5f * timeLength;
			if (time <= halfTimeLength)
			{	// normal interpolation
				normalizedTime = interpolationFunc(time / halfTimeLength);
			}else
			{	// reverse interpolation
				normalizedTime = interpolationFunc(2.0f - (time / halfTimeLength));/*1.0f - ((time - halfTimeLength) / halfTimeLength)*/
			}
			
			if (time >= timeLength)
			{
				if (repeatCount == 0)
				{
					time = timeLength;
					normalizedTime = 0.0f;
					state |= STATE_FINISHED;
				}else
				{
					time -= timeLength;
					repeatCount--;
				}
			}
		}else // 
		{
			time += timeElapsed*timeMultiplier;
			normalizedTime = interpolationFunc(time / timeLength);
			if (time >= timeLength)
			{
				if (repeatCount == 0)
				{
					time = timeLength;
					normalizedTime = 1.0f;
					state |= STATE_FINISHED;
				}else 
				{
					time -= timeLength;
					repeatCount--;
				}
			}
		}
	}
}
void UIHoleTransition::Update(float32 timeElapsed)
{
	UIScreenTransition::Update(timeElapsed);
	normalizedTime = currentTime / duration;
	
	float scaleCoef = 1.0f;
	if (normalizedTime <= 0.5f)scaleCoef = interpolationFunc(1.0f - normalizedTime * 2.0f);
	else scaleCoef = interpolationFunc((normalizedTime - 0.5f) * 2.0f);
		
	for (int k = 0; k < clipPoly.pointCount; ++k)
	{
		realPoly.points[k] = clipPoly.points[k];
		realPoly.points[k] -= Vector2(GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f);
		realPoly.points[k] *= scaleCoef;
		realPoly.points[k] += Vector2(GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f);
	}
}
void UIScreenTransition::Update(float32 timeElapsed)
{
	currentTime += timeElapsed;
	normalizedTime = interpolationFunc(currentTime / duration);
	if (currentTime >= duration)
	{
		currentTime = duration;
		nextScreen->SystemDidAppear();
		ReleaseRenderTargets();
		// go to next screen
		UIControlSystem::Instance()->ReplaceScreen(nextScreen);
		UIControlSystem::Instance()->UnlockInput();
		
		/*
			Right now we are in update so when we change control we miss Update for new screen
			Here we call update control to make calls to update / draw sequential and avoid problem with missing Update
			We pass current timeElapsed because we miss current frame time
		 */
		nextScreen->SystemUpdate(timeElapsed); // 
	}
}