Search code examples
javaresizelibgdxscale

Difference between scale and resize texture


I'm using texture regions in libgdx and I wanted to resize my image. However I found that I could do that task by 2 ways:

batch.draw(texReg, 0, 0, 0, 0, texReg.getRegionWidth()*2, texReg.getRegionHeight()*2, 1, 1, 0);

batch.draw(texReg, 0, 0, 0, 0, texReg.getRegionWidth(), texReg.getRegionHeight(), 2, 2, 0);

What's the difference between this 2 methods? In the first I am modifying width and height parameters and in the other the scaleX and scaleY parameters. Which one is more efficient?


Solution

  • Since you used 0,0 for the origin, there is no difference between these two. If you used a different origin, then the first one would scale the sprite relative to its bottom left corner, whereas the second one would scale it relative to the origin point.

    From looking at the source, the first one results in two fewer multiplication operations, but that's not enough to have any significance. The draw method has dozens of operations.