LibGDX's TexturePacker with gradle
Asked Answered
F

1

9

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

This gave the error

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

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.

So I have several questions:

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

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

  3. 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.)

Forepaw answered 15/6, 2015 at 22:53 Comment(0)
C
11

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

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"]
}
Consultant answered 27/7, 2015 at 5:30 Comment(3)
This is working but i had to change " to ' in the input/output path. Now how do i set the maxWidth and maxHeight? i tried def settings = new TexturePacker.Settings() settings.maxHeight = 4096 settings.maxWidth = 2048, but it failes with general error.Colorimeter
I usually just add a pack.json in my foldersConsultant
An improvement to this solution would be to name the Strings in texturePacker more meaningfully rather than using an array.Forepaw

© 2022 - 2024 — McMap. All rights reserved.