【问题标题】:LibGDX's TexturePacker with gradle带有 gradle 的 LibGDX 的 TexturePacker
【发布时间】:2015-08-31 14:30:26
【问题描述】:

我正在尝试根据here 的说明创建一个运行 TexturePacker 的 gradle 任务。 (请注意,我使用的是 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])
  }
}

这给出了错误

无法解析 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 运行时如何指定输入和输出目录以及 atlas 文件? (假设前两个问题已经解决。)

【问题讨论】:

    标签: android libgdx texturepacker


    【解决方案1】:

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

    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"]
    }
    

    【讨论】:

    • 这是可行的,但我必须在输入/输出路径中将“更改为”。现在如何设置 maxWidth 和 maxHeight?我尝试了 def settings = new TexturePacker.Settings() settings.maxHeight = 4096 settings.maxWidth = 2048,但失败并出现一般错误。
    • 我的文件夹中通常只有add a pack.json
    • 对此解决方案的改进是更有意义地命名texturePacker 中的字符串,而不是使用数组。
    猜你喜欢
    • 1970-01-01
    • 2012-06-15
    • 2014-05-06
    • 2019-12-05
    • 2016-05-16
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 2023-03-31
    相关资源
    最近更新 更多