Jump to content
  • Advertisement
Sign in to follow this  
Daichi

ID3DXSprite Tilesheet Mirror/Flip?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I'm currently loading an 8x8 image Tilesheet of 128x128 pixel images into a IDirect3DTexture9. I'm trying to add functionality to my drawing routine for a mirrored tile image. I've read that I need to use Scaling and set the Axis I want to flip to -1.0. I'm not having much luck with this, It seems to be screwing with the position of how I grab my sprite on my Tilesheet texture. Do I need to subtract the image size somewhere? If so, How would I retrieve the texture size from the IDirect3DTexture9 object? Here is a tiny code fragment edited for easier reading.
RECT Source = {
   _Tilex*TileWidth, 
   _Tiley*TileHeight,
   _Tilex*TileWidth+TileWidth,
   _Tiley*TileHeight+TileHeight
};

D3DXMATRIX transform;
D3DXMatrixTransformation2D(&transform,NULL,NULL,&D3DXVECTOR2(-1, 1),NULL,NULL,NULL);
pSprite->GetTransform(&transform);

pSprite->Draw(pTexture, &Source, pCenter, pPosition, Color)
-Daichi

Share this post


Link to post
Share on other sites
Advertisement
Just negate your coordinate too [smile]

If drawing a sprite at xy coordinate 5,3, and you want to flip the x axis, provide the -1,1,1 scaled matrix and draw the sprite to -5,3.

In your example, I believe you would need to negate pPosition.x for horizontal flips, or negate pPosition.y for vertical flips.

edit:

Err, umm, I missed something. For some reason, ID3DXSprite is flipping the texture coordinates as well. So I guess the RECT structure that you pass to it also needs to be flipped. It's left side and right side swapped for x, top and bottom for y. Sorry for missing that.
RECT Source = {
_Tilex*TileWidth+TileWidth,
_Tiley*TileHeight,
_Tilex*TileWidth,
_Tiley*TileHeight+TileHeight
};

Share this post


Link to post
Share on other sites
Ah. I feel silly having to ask this, but how do I change my D3DXVECTOR3 pPosition?

-Daichi :/

Share this post


Link to post
Share on other sites
I would have to see the whole function to give you the best answer. But you could replace..

pPosition
with
D3DXVECTOR3( -pPosition.x, pPosition.y, pPosition.z )

to mirror the x axis only.

Share this post


Link to post
Share on other sites
Yeah, I just figured that out, IntelliSence wasn't showing me the properties for a D3DXVECTOR3 object. Thanks a bunch, that was very helpful. Now I'll go relax for a bit.

-Daichi :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!