Unity : DrawTextureWithTexCoords Example and Tutorial

A few weeks earlier I was confused in how to use the DrawTextureWithTexCoords, searching with google gave no results, yes there are fews example and perhaps tips, but those are unclear to me.

Fortunatelly after trial and error, I finally understand how this function really works, stick to me for more explanation.

Unity Documentation :

DrawTextureWithTexCoords(Rect position, Texture image, Rect texCoords, bool alphaBlend = true);

Position : Rectangle on the screen to draw the texture within.
Texture : Texture to display.
texCoords : How to scale the image when the aspect ratio of it doesn’t fit the aspect ration to be drawn within.
alphablend : Whether to alpha blend the image on to the display (the default). If false, the picture is drawn on the display.

For more simple explanation,

Continue reading »

How to use animation offset in libgdx from texturepacker

While trying some new things after working all days, I encountered something annoying .. when I used texturepacker gui from codeandweb, the packer packs my image into one and use offset to maximize its compression.

This kind of packing is actually good, but it’s a little annoying because we must set the offset in libgdx to actually make the animation position line-up.

Packed by texturepacker
Packed by texturepacker

I browsed through google to find how to actually get the offset and apply it to the animation function in libgdx, but luck not in my side for a whole day … ah, as reminder I used this code to apply rotation from the left bug, because if you used the sprite as it is, you will get the same as the sprite above for animation.

Continue reading »