Jump to content
  • Advertisement
Sign in to follow this  
Amnesty2

Scaling Sprites trouble

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

I'm creating a 2D game with DX9 using sprites and want to make a hit point bar.
I created a image that with no scale would fill the hud's life bar to 100% because the bar is exactly the right size when drawn.

It works fine when the scale is 1.0 but at any other value it is not right.
It scales fine the problem is it is drawn in the wrong position.

instead of the it being drawn at
pos1.x = 12;
pos1.y = 768 - 48 + 24;

it looks like it is being drawn at this position
pos1.x = 6;

And then it over laps part of the HUD graphic.

I don't understand why its moving the sprite to the left.. It gets worse the more scale there is.


[source]
D3DXVECTOR3 pos1;
pos1.x = 12;
pos1.y = 768 - 48 + 24;
pos1.z = 0;

D3DXMATRIX scale_matrix;
D3DXVECTOR2 scale(0.5f,1.0f); // 50% scale in then x-direciton only
D3DXMATRIX original;

sprite_obj->GetTransform(&original);

D3DXMatrixTransformation2D(&scale_matrix,NULL,0,&scale,NULL,NULL,NULL);
sprite_obj->SetTransform(&scale_matrix);
window::sprite_obj->Draw( txt_manager.get_texture("hp"),NULL,NULL,&pos1, D3DCOLOR_XRGB(255,255,255));
sprite_obj->SetTransform(&original);
[/source]

do i need to use a translation vector? If so how would i make it right every scale value?
Why is this happening?


Also how can i set the transparency of a sprite at run time before it is drawn?

Share this post


Link to post
Share on other sites
Advertisement
Use this instead

[font=Consolas,][color=#000000]
D3DXVECTOR2 pos1;
pos1.x = 12;
pos1.y = 768 - 48 + 24;

D3DXMATRIX scale_matrix;
D3DXVECTOR2 scale(0.5f,1.0f); // 50% scale in then x-direciton only
D3DXMATRIX original;

sprite_obj->GetTransform(&original);

D3DXMatrixTransformation2D(&scale_matrix,NULL,0,&scale,NULL,NULL,&pos1);
sprite_obj->SetTransform(&scale_matrix);
window::sprite_obj->Draw( txt_manager.get_texture("hp"),NULL,NULL,NULL, D3DCOLOR_XRGB(255,255,255));
sprite_obj->SetTransform(&original);
[/font]



[font=Consolas,][color=#000000]That tranformation you apply on the sprite is applied on all the information you provide in the Draw Function.[/font]



[font=Consolas,][color=#000000]Basically you were scaling after you translate the image, you have to translate after you had it scaled[/font]

Edited by Such1

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!