









In the previous tutorial "2D Animation with Direct3D Part 1", you may ask yourself, how to display character that facing right direction into the other way (facing left direction) or simply called mirroring. Do we have to create to two sprites (facing left and right direction) for every animation frames?
Of course we do not have to spend more resources than we actually need to create this mirroring effect. It's not too hard. What you need is only an understanding about how scaling is done. For example, we have following variable:
var scale:TD3DXVector2;
if we set scale with:
scale.x:=1;
scale.y:=1;
then sprite polygon will be displayed as it was because multiplication of a value with one, yields value of itself.If we set scale with number bigger than one, polygon will be scaled according to value of each axis.
scale.x:=2;
scale.y:=1.5;
If sprite polygon is 100x100, then after transformation, polygon will become 200x150. Sprite will look stretched. Interesting thing happens if we set x or y or both axis with negative value. Sprite will look mirrored. If we set scale with:
scale.x:=-1;
scale.y:=1;
sprite will be mirrored horizontally with line of mirror is at (0,0) until (0,Height) and if we set
scale.x:=1;
scale.y:=-1;
sprite will be mirrored vertically with line of mirror at (0,0) until (0,Width).
Ok, just download its source code here to view mirroring process result.
Happy coding!
Do you like this article? Help this website improve by donating. Any amounts is appreciated.
Or you can help by bookmarking this page.
Bookmark this on Delicious