private void packtiles(Collection<Tile> tiles, Coord tsz) {
			int min = -1, minw = -1, minh = -1;
			int nt = tiles.size();
			for (int i = 1; i <= nt; i++) {
				int w = Tex.nextp2(tsz.x * i);
				int h;
				if ((nt % i) == 0)
					h = nt / i;
				else
					h = (nt / i) + 1;
				h = Tex.nextp2(tsz.y * h);
				int a = w * h;
				if ((min == -1) || (a < min)) {
					min = a;
					minw = w;
					minh = h;
				}
			}
			TexIM packbuf = new TexIM(new Coord(minw, minh));
			Graphics g = packbuf.graphics();
			int x = 0, y = 0;
			for (Tile t : tiles) {
				g.drawImage(t.img, x, y, null);
				t.tex = new TexSI(packbuf, new Coord(x, y), tsz);
				if ((x += tsz.x) > (minw - tsz.x)) {
					x = 0;
					if ((y += tsz.y) >= minh)
						throw (new LoadException(
								"Could not pack tiles into calculated minimum texture",
								Resource.this));
				}
			}
			packbuf.update();
		}