Stretch an image / texture

37 views
Skip to first unread message

Ian Harrigan

unread,
Nov 9, 2015, 3:36:07 PM11/9/15
to Flambe
Hi All,

So im wondering what is the best way to stretch and image in sections in flambe. This is for a scale9 image, so the top, left, bottom & right sections get stretched to the correct size. Ive seen graphics.drawSubTexture, which is almost what im after, except i would also need a destWidth & destHeight, is this something any one has any tips on?

I presume i could also do it by cutting up the image in memory and creating 9 separate textures out of it, then creating ImageSprites from them and using the scaleX/Y to get the required size and put them in a parent sprite, but these seems like real overkill, when all i want is to draw to a sprites graphics in certain ways without all this overhead and creating new textures all over the place.

Any help would be greatly apprecaited!

Cheers,
Ian

Mark Knol

unread,
Nov 9, 2015, 4:42:12 PM11/9/15
to Flambe
A subtexture isn't a "real" texture, it's just a rectangle in a referenced texture, so in most cases it's nice to use them. (unless the size constantly changes of these subtextures)

The easiest way to do it, is to use subTextures with ImageSprite. So 9 ImageSprite's for that. But yes, thats more expensive and a bit of overkill.

To do it more nicely, you would override the Sprite draw function and draw the textures yourself. I think it's still good to have 9 subtextures. You should save, scale and restore the graphics state. Something like this:



Ian Harrigan

unread,
Nov 9, 2015, 5:31:08 PM11/9/15
to Flambe
Great! Thanks ill have a play,

Cheers, Ian
Reply all
Reply to author
Forward
0 new messages