# ID3DXSprite scaling question

This topic is 4449 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am working on a RTS game where the player can scroll around the world by moving the window. If I leave the scale set to 1.0f everything works perfectly, but when I scale the buildings to 0.5f or anything for that fact they seem to wander with the movement of the window. My question is how do determine the screen coordinates of a texture that has been scaled. I am basically keeping up with the current viewport location and modifying each object based on the window's position. I have to double the win.left and win.top coordinates to make a scale of 0.5f work, but when I have it set to a scale of 1.0f I don't have to modify anything. It could have something to do with the way I am scaling the building
	D3DXMATRIX temp;
D3DXVECTOR2 scale(0.5f,0.5f);
D3DXMatrixTransformation2D(&temp, NULL,0.0f,&scale, NULL, 0.0f, NULL);
g_engine->GetSprite()->SetTransform(&temp);


Thanks in advance for any tips

##### Share on other sites
The Sprite's screen location is also scaled by the same transformation matrix. That means that if you're are scaling by a factor of 0.5, and you want to Sprite to be at location X, you need to divide it by the scaling factor: newX = oldX / 0.5. This is then scaled by the scale factor, which is 0.5, and is thus eliminated, leaving the actual position the Sprite is drawn to as X.

Since you're using a 2D transformation matrix, you probably won't have to scale the Z value at all.

Hope this helps.

##### Share on other sites
Quote:
 Original post by sirobThe Sprite's screen location is also scaled by the same transformation matrix. That means that if you're are scaling by a factor of 0.5, and you want to Sprite to be at location X, you need to divide it by the scaling factor: newX = oldX / 0.5. This is then scaled by the scale factor, which is 0.5, and is thus eliminated, leaving the actual position the Sprite is drawn to as X.Since you're using a 2D transformation matrix, you probably won't have to scale the Z value at all.Hope this helps.

That makes a lot of sense!

Thank you

1. 1
2. 2
3. 3
Rutin
24
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633650
• Total Posts
3013123
×