View Single Post
09-15-14, 12:07 AM   #19
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
It's not about avoiding creating an extra texture object, it's about avoiding the need for doing math to determine the necessary texture coordinates. For example, let's say you have the following:



The whole image is 700x400, and contains 3 pictures of a kitten (2 smaller on the left, 1 bigger on the right). Let's say you have an atlas for the top left picture, covering an area 270px wide and 200px high, and you want to display a 150px square zooming in on the kitten's adorable little fuzzy face. (And look at those spots! Don't you just want to scratch its little chin and rub its little belly? )

Without the atlas:

Code:
texture:SetTexture("Path\\To\\Kittens")
texture:SetTexCoord(0.1114, 0.3257, 0.02, 0.395) -- 78/700, (78+150)/700, 8/400, (8+150)/400
Obviously that's fine, but what happens later if you change your mind and want to show the whole kitten? Well, you have to go look at the source image and manually figure out what the coordinates for that are:

Code:
texture:SetTexCoord(0, 0.3857, 0, 0.5) -- 0, 270/700, 0, 200/400
Now let's try with the atlas. Kitten face only:

Code:
texture:SetTexture("Path\\To\\Kittens")
texture:SetAtlas("Kitten-One-Of-Three")
texture:TexCoord(0.2888, 0.8444, 0.04, 0.79) -- 78/270, (78+150)/270, 8/200, (8+150)/200
Pretty similar in terms of effort (calculating coordinates) as without an atlas. But, when you change your mind later and want to show the whole kitten, it's much easier:

Code:
texture:SetTexCoord(0, 1, 0, 1)
Basically it slices up the source file before applying it to your texture object, so as far as your object is concerned, the file doesn't contain anything outside of the atlas area.

Also keep in mind that you cannot create your own atlases. You can only use the ones already defined by Blizzard. This means that they're mainly only useful if you're creating things that graphically match the default UI.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 09-15-14 at 12:09 AM.