ID3DXSprite Tilesheet Mirror/Flip?

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

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 on other sites
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 on other sites
Ah. I feel silly having to ask this, but how do I change my D3DXVECTOR3 pPosition?

-Daichi :/

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 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

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 15
• 21
• 26
• 11