读取动画变量值

应用程序每次绘制时,它都应读取表示要进行动画处理的视觉特征的动画变量的当前值。

概述

在绘制框架时,应用程序可以使用 IUIAnimationVariable::GetValueIUIAnimationVariable::GetIntegerValue 方法请求将影响帧内视觉对象的任何动画变量的值。 可以将动画变量剪辑为 setLowerBoundSetUpperBound) (值范围,并请求使用 setRoundingMode () 指定的舍入方案将其值舍入为整数。

而不是读取每个帧的所有变量的值, 应用程序可以使用 IUIAnimationVariable::SetVariableChangeHandlerIUIAnimationVariable::SetVariableIntegerChangeHandler 方法注册一个或多个变量更改处理程序,以仅当变量的值 (IUIAnimationVariableChangeHandler::OnValueChanged) 或舍入值 (IUIAnimationVariableIntegerChangeHandler::OnIntegerValueChanged) 。 若要标识传递给变量更改处理程序的变量,应用程序可以使用 IUIAnimationVariable::SetTag 方法将标记应用于变量。 这些是对象 (IUnknown*) ,由应用程序解释的整数对。

示例代码

以下示例代码取自 Windows 动画示例 网格布局中的 Thumbnail.cpp;请参阅 CMainWindow::Render 方法。 它使用 GetValue 方法将值读取为浮点值。

// Get the x-coordinate and y-coordinate animation variable values

DOUBLE x=0;
hr = m_pAnimationVariableX->GetValue(&x);
if (SUCCEEDED(hr))
{
    DOUBLE y=0;
    hr = m_pAnimationVariableY->GetValue(&y);
    if (SUCCEEDED(hr))
    {
        // Draw the object

        ...

    }
}

以下示例代码取自 Windows 动画示例 计时器驱动动画中的 MainWindow.cpp;请参阅 CMainWindow::D rawBackground 方法。 它使用 GetIntegerValue 方法将值读取为整数值。

// Get the RGB animation variable values

INT32 red;
HRESULT hr = m_pAnimationVariableRed->GetIntegerValue(
    &red
    );
if (SUCCEEDED(hr))
{
    INT32 green;
    hr = m_pAnimationVariableGreen->GetIntegerValue(
        &green
        );
    if (SUCCEEDED(hr))
    {
        INT32 blue;
        hr = m_pAnimationVariableBlue->GetIntegerValue(
            &blue
            );
        if (SUCCEEDED(hr))
        {
            // Set the RGB of the background brush to the new animated value

            ...
                
            // Paint the background

            ...

        }
    }

    ...

}

上一步

在开始此步骤之前,应已完成此步骤: 更新动画管理器和绘制帧

下一步

完成此步骤后,下一步是: 创建情节提要和添加切换效果。

IUIAnimationVariable::GetIntegerValue

IUIAnimationVariable::GetValue

Windows 动画概述