LibGDX的带有gradle的TexturePacker

Cod*_*ice 7 android libgdx texturepacker

我正在尝试创建一个gradle任务,根据此处的说明运行TexturePacker .(请注意,我使用的是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])
  }
}
Run Code Online (Sandbox Code Playgroud)

这给出了错误

无法解析类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文件?(假设前两个问题已经解决了.)

Xav*_*man 10

我通过在我的buildscript依赖项中添加gdx-tools来实现它:

buildscript{
    dependencies {
       ...
       classpath 'com.badlogicgames.gdx:gdx-tools:1.5.4'
    }
}
Run Code Online (Sandbox Code Playgroud)

通过这样做,我的桌面的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])
    }
}
Run Code Online (Sandbox Code Playgroud)

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

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