android - LibGDX 的 TexturePacker 与 gradle

标签 android libgdx texturepacker

我正在尝试根据说明创建一个运行 TexturePacker 的 gradle 任务 here . (请注意,我使用的是 Android Studio 及其目录结构,而不是 Eclipse。)我首先将以下内容添加到 Android Studio 项目的 build.gradle:

import com.badlogic.gdx.tools.texturepacker.TexturePacker
task texturePacker << {
  if (project.ext.has('texturePacker')) {
    logger.info "Calling TexturePacker: "+texturePacker
    TexturePacker.process(texturePacker[0], texturePacker[1], texturePacker[2])
  }
}

这给出了错误

unable to resolve class com.badlogic.gdx.tools.texturepacker.TexturePacker

texturePacker 任务移动到桌面项目中的 build.gradle 会产生相同的错误。根据http://www.reddit.com/r/libgdx/comments/2fx3vf/could_not_find_or_load_main_class_texturepacker2/ ,我还需要将 compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion" 添加到桌面项目依赖项下的根 build.gradle 中。当我这样做时,我仍然遇到同样的错误。

所以我有几个问题:

  1. texturePacker 任务的正确位置在哪里?我应该把它放在哪个 build.gradle 中?

  2. 如何解决依赖问题和 unable to resolve class... 错误?

  3. 在使用 gradle 运行时,如何指定输入和输出目录以及图集文件? (假设前两个问题都解决了。)

最佳答案

我通过将 gdx-tools 添加到我的构建脚本依赖项来让它工作:

buildscript{
    dependencies {
       ...
       classpath 'com.badlogicgames.gdx:gdx-tools:1.5.4'
    }
}

通过这样做,我桌面的 build.gradle 能够导入纹理打包器类:

import com.badlogic.gdx.tools.texturepacker.TexturePacker
task texturePacker << {
    if (project.ext.has('texturePacker')) {
        logger.info "Calling TexturePacker: "+ texturePacker
        TexturePacker.process(texturePacker[0], texturePacker[1], texturePacker[2])
    }
}

请注意,您的桌面项目的 ext 需要定义 texturePacker:

project.ext {
    mainClassName = "your.game.package.DesktopLauncher"
    assetsDir = new File("../android/assets");
    texturePacker = ["../images/sprites", "../android/assets", "sprites"]
}

关于android - LibGDX 的 TexturePacker 与 gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30856278/

相关文章:

android - 为组创建离线 SQLite 数据库

android - 使用 5 次后阻止使用

Android:更新另一个应用程序中使用的 SQLite 表

android - 如何在 Android 的自定义 ListView 中使用搜索功能

java - 无法将 libGDX 项目导入 Eclipse。

cocos2d-iphone - Assets 目录可以消除 Sprite 表中 iOS 设备资源扩展的需要吗?

java - LibGDX 相机旋转问题

java - 是否可以在 LibGDX 中创建映射到数组的网格布局?

android - 我们是否需要在 cocos2dx 中使用 Sprite 作为 2 的幂

android - Andengine - 使用 TexturePacker Spritesheet 时内存使用量增加