Reputation: 3164
When I'm using the SpriteBatch.Draw()
method I can get vertical or horizontal scaling. For example:
new Vector2(1.0f, 2.0f)
it means that my sprite will expand the Y-axis. How can I get it to diagonally expand (for example 45 or 70 degrees)?
(Update from comments)
I have circle sprite and this picture contains shadows and glare, I need to stretch this circle (make ellipse) and rotate it, but I want the shadow does not change its position into ellipse. Rotation and scaling change every frame.
This picture from World Of Goo game:
Upvotes: 0
Views: 1309
Reputation: 15154
First scale it horizontally and then vertically. If it is 45 degrees, you will scale the same in both directions, if its another angle, you can compute the scales using simple sin/cos functions.
EDIT:
C# example:
float angle = 70; // Direction in degrees
float amount = 1; // By how many percent (1 = 100 %)
float radAngle = (angle / 180) * Math.PI;
float xratio = (1 + Math.cos(radAngle)) * amount;
float yratio = (1 + Math.sin(radAngle)) * amount;
// Then just make a new Vector2(xratio, yratio)
Beware of bugs in that example, I haven't tested it. Wouldn't it also be easier for you to just stretch the sprite using the Vector2 directly?
SpriteBatch.Draw(/* Some stuff */, new Vector2(2.0, 3.0), /* some more stuff */); // Scale 2x in horizontal and 3x in vertical direction
Upvotes: 1