I'm trying to render two sprites... One of them, the player's cursor, is controlled by the mouse. That sprite follows the mouse, no problem.
I also have a corner sprite that doesn't move. With this code, it also follows the mouse around the screen, even though it never changes position.
The render function:
void Render()
{
// Start rendering on the backbuffer.
if (d3ddev->BeginScene())
{
// Black background
d3ddev->ColorFill(backBuffer, NULL, D3DCOLOR_XRGB(0, 0, 0));
sprite->Begin(D3DXSPRITE_ALPHABLEND);
D3DXVECTOR2 pos;
pos.x = redHand.pos.x;
pos.y = redHand.pos.y;
D3DXVECTOR2 scaling(1.0f, 1.0f);
D3DXMATRIX spriteMatrix;
D3DXMatrixTransformation2D(&spriteMatrix, 0, 0, &scaling, 0, 0, &pos);
sprite->SetTransform(&spriteMatrix);
RECT srcRect;
srcRect.left = 0;
srcRect.right = 32;
srcRect.top = 0;
srcRect.bottom = 32;
sprite->Draw(playerTexture, &srcRect, NULL, NULL, D3DCOLOR_XRGB(255, 255, 255));
srcRect.left = 0;
srcRect.right = 200;
srcRect.top = 0;
srcRect.bottom = 200;
sprite->Draw(cornerTexture, &srcRect, NULL, NULL, D3DCOLOR_XRGB(255, 255, 255));
sprite->End();
d3ddev->EndScene();
}
// Flip back buffer to the screen
d3ddev->Present(NULL, NULL, NULL, NULL);
}
The update function:
void Update(float delta, HWND hWnd)
{
PollMouse();
// Move the hand sprite.
redHand.pos.x += MouseX();
if (redHand.pos.x > WINDOW_WIDTH - redHand.width)
{
redHand.pos.x = WINDOW_WIDTH - redHand.width;
}
else if (redHand.pos.x < 0)
{
redHand.pos.x = 0;
}
redHand.pos.y += MouseY();
if (redHand.pos.y > WINDOW_HEIGHT - redHand.height)
{
redHand.pos.y = WINDOW_HEIGHT - redHand.height;
}
else if (redHand.pos.y < 0)
{
redHand.pos.y = 0;
}
// Check for escape key to exit.
if (KEY_DOWN(VK_ESCAPE))
{
gameIsRunning = false;
}
}
As you can see, the Update function never changes the position of the corner sprite. Any ideas why it would be following my mouse around along with the cursor sprite?