本文介绍了LibGDX的Gradle的TexturePacker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am attempting to create a gradle task which runs TexturePacker according to the instructions here. (Note that I am using Android Studio and its directory structure rather than Eclipse.) I first added the following to the Android Studio project's 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])
  }
}

这给出了错误

在桌面项目中将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中.这样做时,我仍然遇到相同的错误.

Moving the texturePacker task to build.gradle in the desktop project produces the same error. According to http://www.reddit.com/r/libgdx/comments/2fx3vf/could_not_find_or_load_main_class_texturepacker2/, I also need to add compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion" to the root build.gradle under the desktop project's dependencies. When I do so, I still get the same error.

所以我有几个问题:

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

  1. Where is the correct place for the texturePacker task? Which build.gradle do I put this in?

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

How do I solve the dependency issue and the unable to resolve class... error?

在使用gradle运行时如何指定输入和输出目录以及atlas文件? (假设前两个问题已解决.)

How do I specify the input and output directories and the atlas file when running this with gradle? (Assuming the first two questions are solved.)

推荐答案

我通过在我的buildscript依赖项中添加gdx-tools使它起作用:

I got it working by adding gdx-tools to my buildscript dependencies:

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

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

by doing this, my desktop's build.gradle was able to import the texture packer class:

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:

please note that your desktop project's ext will need to have texturePacker defined:

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

这篇关于LibGDX的Gradle的TexturePacker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 13:28