PDA

View Full Version : scale texture from center



mapleegreen
11-30-2011, 03:33 AM
I want to canvas draw and scale texture from the texture center.


scaleSize = 1;
......
Canvas.DrawTile(Images[Idx], width* scaleSize, height* scaleSize,ImagesUVs[Idx].U, ImagesUVs[Idx].V, ImagesUVs[Idx].UL, ImagesUVs[Idx].VL, DrawColor,true);
scaleSize += 0.01;

if(scaleSize >2)
{
scaleSize = 1;
}
the code above ,always make texture extend to right and down.Is there a good way scale the texture from the texture center?

ffejnosliw
11-30-2011, 03:36 AM
You would have to do it manually by offsetting the drawing position left and up half the width and height of the tile (respectively) from the point you want it centered on.

Angel_Mapper
11-30-2011, 03:39 AM
What does your Canvas.SetPos call look like for that? That's where you'd be doing the movement. Basically, instead of thinking about it being from the center think about it as moving the top left corner by half of the scale.

[edit] Ninja'd by Jeff!

mapleegreen
11-30-2011, 04:15 AM
Canvas.SetPos(OwnerScene.Left + Left - Canvas.OrgX, OwnerScene.Top + Top - Canvas.OrgY);


above is my origin setpos,when I scale the texture ,I change to


Canvas.SetPos(OwnerScene.Left + Left - Canvas.OrgX-(width* (scaleSize-1)), OwnerScene.Top + Top - Canvas.OrgY-(height* (scaleSize-1)));


but still have no effect,only change the sacle direction.The lower right corner of the texture become the origin

mapleegreen
11-30-2011, 04:18 AM
What does your Canvas.SetPos call look like for that? That's where you'd be doing the movement. Basically, instead of thinking about it being from the center think about it as moving the top left corner by half of the scale.

[edit] Ninja'd by Jeff!

thanks,the pos change should is half of the scale.