Sign in to follow this  
Tipotas688

Sprite Flip

Recommended Posts

Tipotas688    86
Hello! I am making a 2D game in C++ and Direct3D and I want to flip my ID3DXSprite. I know I should be using shaders but collision detection is in place, everything else is in place apart from the flipping part. I tried using: D3DXMatrixTransformation2D(&s_matrix, NULL, 0, &s_scaling, NULL, 0, &s_position); s_sprite->SetTransform(&s_matrix); with scaling to -1 but my sprite disappeared from the screen. if I set s_position as null it wont change at all. Is there any way to flip the UV data of the texture? Any other ways, anything that would do the horizontal flipping. Thanks

Share this post


Link to post
Share on other sites
Tipotas688    86
I did try multiplying my position with -1 but it didnt work... still didn't appear

s_scaling.x = -s_scaling.x;
s_position->x = -s_position->x;
s_position->y = s_position->y;
D3DXMatrixTransformation2D(&s_matrix, NULL, 0, &s_scaling, NULL, 0, s_position);

[Edited by - Tipotas688 on February 17, 2010 12:49:38 PM]

Share this post


Link to post
Share on other sites
bennyboy2    100
The sprite is an interface to the drawing surface, rather than a graphical object. If you flip it, coordinates flip around the center of the screen.
If you translate it, then the center of the sprite != the center of the screen, and you have to account for that.

See:
http://www.gamedev.net/community/forums/topic.asp?topic_id=470114

Unless you are scrolling the screen, I wouldn't change the translation of the sprite. I'd scale the sprite to -1, but do my translation offset at Sprite->Draw() (with neg coords for the position offset)


I like your idea of flipping UVs. I found:
http://msdn.microsoft.com/en-us/library/ee422052(VS.85).aspx

I'm not sure if this does the trick, but it might be something worth playing with?

Share this post


Link to post
Share on other sites
Tipotas688    86
What I was trying and is told above is correct, I was having some problems with my positioning pointers (not too advanced with C++ yet but getting there)

Yeah putting translation into the mix didn't help but since I had tried everything from flipping the sprite in 3D space to breaking the DXUT's camera I thought putting translation into the mix would help a bit.

Thanks all :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this