Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Scaling Sprites trouble


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Amnesty2   Members   -  Reputation: 203

Like
0Likes
Like

Posted 05 June 2012 - 07:20 PM

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.



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



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?

Sponsor:

#2 Such1   Members   -  Reputation: 435

Like
1Likes
Like

Posted 07 June 2012 - 01:09 PM

Use this instead

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


That tranformation you apply on the sprite is applied on all the information you provide in the Draw Function.


Basically you were scaling after you translate the image, you have to translate after you had it scaled


Edited by Such1, 07 June 2012 - 01:12 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS