Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Scaling sprites in 2D

Started by ta0soft Feb 24, 2012 at 10:08 PM 0 replies 2.5k views
Original Post
ta0soft
ta0soft
I'm trying to create a resizable UI using sprites in SlimDX. I am drawing them in screen/window coordinates using Sprite.Draw, but I can't figure out how to scale sprites in screen coordinates.

For instance I need 9 sprites to draw the background of a button control. One for each corner and edge of the rectangle, and one for the center area. I want to stretch the center sprite so it fills the buttons background when it changes size.

ss.jpg

I know how to get the scalar value of 2 integers but I don't know how this would apply in scaling the sprite. Any help would be greatly appreciated.

[source]
float scaleWidth = ?
float scaleHeight = ?

Sprite.Transform = Matrix.Transformation2D(new Vector2(p_Bounds.X + MiddleLeft.Width, p_Bounds.Y + TopCenter.Height), 0.0f, new Vector2(scaleWidth, scaleHeight), new Vector2(), 0.0f, new Vector2());
Sprite.Draw(Texture, MiddleCenter, new Vector3(), new Vector3(p_Bounds.X + MiddleLeft.Width, p_Bounds.Y + TopCenter.Height, 0.0f), new Color4(Color.White));
[/source]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.