LibGDX TexturePacker with gradle

I am trying to create a gradle task that launches a TexturePacker as instructed here . (Note that I'm using Android Studio and its directory structure, not Eclipse.) First, I added the following to the Android Studio build.gradle project:

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

It gave an error

cannot resolve class com.badlogic.gdx.tools.texturepacker.TexturePacker

Moving a texturePacker task to build.gradle in a desktop project causes 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 build.gradle root directory depending on project on the desktop. When I do this, I still get the same error.

So, I have a few questions:

  • Where is the right place for the texturePacker task? Which build.gradle do I put this?

  • How to solve the dependency problem and unable to resolve class... error?

  • How to specify input and output directories and atlas file at startup using gradle? (Suppose the first two questions are resolved.)

+6
source share
1 answer

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

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

by doing this, my build.gradle desktop 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]) } } 

note that your desktop development project should have texturePacker value:

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

Source: https://habr.com/ru/post/989165/


All Articles