當前位置: 首頁>>代碼示例>>Java>>正文


Java TexturePacker.addImage方法代碼示例

本文整理匯總了Java中com.badlogic.gdx.tools.texturepacker.TexturePacker.addImage方法的典型用法代碼示例。如果您正苦於以下問題:Java TexturePacker.addImage方法的具體用法?Java TexturePacker.addImage怎麽用?Java TexturePacker.addImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.badlogic.gdx.tools.texturepacker.TexturePacker的用法示例。


在下文中一共展示了TexturePacker.addImage方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: performPacking

import com.badlogic.gdx.tools.texturepacker.TexturePacker; //導入方法依賴的package包/類
private void performPacking(PackModel packModel, PageFileWriter pageFileWriter) throws Exception {
    Array<ImageEntry> imageEntries = collectImageFiles(packModel);
    if (imageEntries.size == 0) {
        throw new IllegalStateException("No images to pack");
    }

    deleteOldFiles(packModel);
    String filename = obtainFilename(packModel);

    TexturePacker packer = new TexturePacker(packModel.getSettings(), pageFileWriter);
    for (ImageEntry image : imageEntries) {
        if (image.ninePatch) {
            packer.addImage(image.fileHandle.file(), image.name, image.splits, image.pads);
        } else {
            packer.addImage(image.fileHandle.file(), image.name);
        }
    }
    packer.pack(new File(packModel.getOutputDir()), filename);
}
 
開發者ID:crashinvaders,項目名稱:gdx-texture-packer-gui,代碼行數:20,代碼來源:PackingProcessor.java

示例2: texturePack

import com.badlogic.gdx.tools.texturepacker.TexturePacker; //導入方法依賴的package包/類
@Override
public void texturePack(Array<FileHandle> handles, FileHandle localFile, FileHandle targetFile) {
    //copy defaults.json to temp folder if it doesn't exist
    FileHandle fileHandle = Gdx.files.local("texturepacker/defaults.json");
    if (!fileHandle.exists()) {
        Gdx.files.internal("defaults.json").copyTo(fileHandle);
    }
    
    Json json = new Json();
    Settings settings = json.fromJson(Settings.class, fileHandle);
    
    TexturePacker p = new TexturePacker(settings);
    for (FileHandle handle : handles) {
        if (handle.exists()) {
            p.addImage(handle.file());
        } else {
            if (localFile != null) {
                FileHandle localHandle = localFile.sibling(localFile.nameWithoutExtension() + "_data/" + handle.name());
                if (localHandle.exists()) {
                    p.addImage(localHandle.file());
                } else {
                    Gdx.app.error(getClass().getName(), "File does not exist error while creating texture atlas: " + handle.path());
                }
            } else {
                Gdx.app.error(getClass().getName(), "File does not exist error while creating texture atlas: " + handle.path());
            }
        }
    }
    p.pack(targetFile.parent().file(), targetFile.nameWithoutExtension());
}
 
開發者ID:raeleus,項目名稱:skin-composer,代碼行數:31,代碼來源:DesktopLauncher.java

示例3: packTilesets

import com.badlogic.gdx.tools.texturepacker.TexturePacker; //導入方法依賴的package包/類
/** Traverse the specified tilesets, optionally lookup the used ids and pass every tile image to the {@link TexturePacker},
 * optionally ignoring unused tile ids */
private void packTilesets (ObjectMap<String, TiledMapTileSet> sets, FileHandle inputDirHandle, File outputDir,
	Settings texturePackerSettings) throws IOException {
	BufferedImage tile;
	Vector2 tileLocation;
	TileSetLayout packerTileSet;
	Graphics g;

	packer = new TexturePacker(texturePackerSettings);

	for (TiledMapTileSet set : sets.values()) {
		String tilesetName = set.getName();
		System.out.println("Processing tileset " + tilesetName);
		IntArray usedIds = this.settings.stripUnusedTiles ? getUsedIdsBucket(tilesetName, -1) : null;

		int tileWidth = set.getProperties().get("tilewidth", Integer.class);
		int tileHeight = set.getProperties().get("tileheight", Integer.class);
		int firstgid = set.getProperties().get("firstgid", Integer.class);
		String imageName = set.getProperties().get("imagesource", String.class);

		TileSetLayout layout = new TileSetLayout(firstgid, set, inputDirHandle);

		for (int gid = layout.firstgid, i = 0; i < layout.numTiles; gid++, i++) {
			if (usedIds != null && !usedIds.contains(gid)) {
				System.out.println("Stripped id #" + gid + " from tileset \"" + tilesetName + "\"");
				continue;
			}

			tileLocation = layout.getLocation(gid);
			tile = new BufferedImage(tileWidth, tileHeight, BufferedImage.TYPE_4BYTE_ABGR);

			g = tile.createGraphics();
			g.drawImage(layout.image, 0, 0, tileWidth, tileHeight, (int)tileLocation.x, (int)tileLocation.y, (int)tileLocation.x
				+ tileWidth, (int)tileLocation.y + tileHeight, null);

			if (isBlended(tile)) setBlended(gid);
			System.out.println("Adding " + tileWidth + "x" + tileHeight + " (" + (int)tileLocation.x + ", " + (int)tileLocation.y
				+ ")");
			packer.addImage(tile, this.settings.atlasOutputName + "_" + (gid-1));
		}
	}

	File outputDirTilesets = getRelativeFile(outputDir, this.settings.tilesetOutputDirectory);
	outputDirTilesets.mkdirs();
	packer.pack(outputDirTilesets, this.settings.atlasOutputName + ".atlas");
}
 
開發者ID:basherone,項目名稱:libgdxcn,代碼行數:48,代碼來源:TiledMapPacker.java


注:本文中的com.badlogic.gdx.tools.texturepacker.TexturePacker.addImage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。