IDCompositionAnimation::AddRepeat 方法 (dcompanimation.h)

加入重複區段,使動畫函式的指定部分重複。

語法

HRESULT AddRepeat(
  [in] double beginOffset,
  [in] double durationToRepeat
);

參數

[in] beginOffset

類型: double

從動畫的開頭到應該開始重複點的位移,以秒為單位。

[in] durationToRepeat

類型: double

beginOffset 所指定開始時間之前動畫部分的持續時間,以秒為單位。 這是將重複的部分。

傳回值

類型: HRESULT

如果函式成功,它會傳回S_OK。 否則,它會傳回 HRESULT 錯誤碼。 如需錯誤碼的清單,請參閱 DirectComposition 錯誤 碼。

備註

如果任一參數為 NaN、正無限大或負無限大,這個方法就會失敗。

因為動畫區段必須依遞增順序新增,所以如果 beginOffset 參數小於或等於上一個區段的 beginOffset 參數,這個方法就會失敗。 如果這是要新增至動畫函式的第一個區段,這個方法也會失敗。

此動畫區段會維持有效狀態,直到下一個區段的開始時間為止。 如果動畫函式不包含更多區段,此區段會無限期地維持作用中。

範例

下列範例會建立包含重複線段的動畫函式,並將動畫套用至縮放轉換的 x 和 y 軸。

HRESULT MyCreateAnimatedScaleTransform(IDCompositionDevice *pDevice, 
                                       IDCompositionVisual *pVisual)
{
    HRESULT hr = S_OK;
    IDCompositionAnimation *pAnimation = nullptr;
    IDCompositionScaleTransform *pScaleTransform = nullptr;

    // Validate the pointers.
    if (pDevice == nullptr || pVisual == nullptr)
        return E_INVALIDARG;
    
    // Create an animation object.
    hr = pDevice->CreateAnimation(&pAnimation);
    if (SUCCEEDED(hr))
    {
        // Add segments to the animation function.
        pAnimation->AddCubic(0, 1, -0.5, 0, 0);
        pAnimation->AddRepeat(3.0, 3.0);
        pAnimation->End(10, .5);

        // Create a scale transform object.
          hr = pDevice->CreateScaleTransform(&pScaleTransform);
    }

    if (SUCCEEDED(hr))
    {
        // Apply the animation to the x and y axes of the scale transform.
        pScaleTransform->SetScaleX(pAnimation);
        pScaleTransform->SetScaleY(pAnimation);

        // Apply the scale transform to the visual.
        hr = pVisual->SetTransform(pScaleTransform);
    }

    if (SUCCEEDED(hr))
    {
        // Commit the composition for rendering.
        hr = pDevice->Commit();
    }

    // Clean up.
    SafeRelease(&pAnimation);
    SafeRelease(&pScaleTransform);

    return hr;
}

規格需求

需求
最低支援的用戶端 Windows 8 [僅限傳統型應用程式]
最低支援的伺服器 Windows Server 2012 [僅限傳統型應用程式]
目標平台 Windows
標頭 dcompanimation.h
程式庫 Dcomp.lib
Dll Dcomp.dll

另請參閱

IDCompositionAnimation