void SelectSprite(int iSelection) { if (iSelection > MAX_SPRITES) { assert(FALSE); return; } float time = float(g_Timer.GetFrameNumber()) / 30; // Apply animation to the sprite. // NOTE: If the sprite is already selected, this call is still used // to apply "wobble" to the sprite. g_pSprites[iSelection].AnimateBoundingBox(g_rcBig, time, ANIMATION_DURATION ); // Unselect the current selection. if ((g_Selection != -1) && (g_Selection != iSelection)) { g_pSprites[ g_Selection ].AnimateBoundingBox(g_rcSmall[ g_Selection ], time, ANIMATION_DURATION ); } g_Selection = iSelection; }
HRESULT RenderFrame(HWND hwnd) { HRESULT hr = S_OK; if (g_pRT && g_pRT->CheckWindowState() == D2D1_WINDOW_STATE_OCCLUDED) { return S_OK; // The render target is occluded. } if (!g_pRT) { // Create the Direct2D resources. hr = CreateDrawingResources(hwnd); } if (SUCCEEDED(hr)) { float fTime = float(g_Timer.GetFrameNumber()) / 30; g_pRT->BeginDraw(); g_pRT->Clear(BACKGROUND_COLOR); // Update and draw each sprite. for (DWORD i = 0; i < MAX_SPRITES; i++) { Sprite *pSprite = &g_pSprites[i]; if (pSprite) { pSprite->Update(g_pRT, fTime); pSprite->Draw(g_pRT); } } // Reset the transform to the identiy matrix. g_pRT->SetTransform(D2D1::Matrix3x2F::Identity()); hr = g_pRT->EndDraw(); } return hr; }