Advertisement Jump to content
Sign in to follow this  

Sprite Rotation? (DirectX 9 C++)

This topic is 3719 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

If by DirectX you mean Direct3D, it depends how you are drawing sprites.

If you are using ID3DXSprite, you set a transform with ID3DXSprite::SetTransform prior to calling ID3DXSprite::Draw which allows you to specify the centre point.

If you are using an orthagonal projection, you can define your sprite vertices in local space around the centre, then multiply a rotation by a transformation to create the matrix to set the world transform before your render.

If you are using textured quads and pretransformed vertices, you need to manually rotate the vertices yourself with sin() and cos() prior to drawing.

If by DirectX you mean DirectDraw, hardware support for sprite rotating is limited. There are methods to do this but you need to check at runtime to see if it is supported. If not, your only option would be to rotate and draw the pixels manually by locking the buffer, which would be slow.

Share this post

Link to post
Share on other sites
This is my code to rotating projectiles:

D3DXMATRIX matRotate;
D3DXVECTOR2 vCenter(16.0f, 16.0f);
D3DXVECTOR2 vPosition(position.x, position.y);

D3DXMatrixTransformation2D(&matRotate, NULL, NULL, NULL, &vCenter, angle, &vPosition);

d3dspt->Draw(artManager.getProjectile(iter->artId)->texture, NULL, NULL, NULL, fullColor);

D3DXMatrixRotationZ(&matRotate, 0);

Position points to a vector of the location in screen coordinates of where you want the texture to be drawn at (after rotation), and put into vPosition

vCenter is the center of the texture (size is 32x32)

angle is a float for the angle in radians.

d3dspt is my sprite object.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!