eowise/gradle-packer-plugin


A Gradle plugin witch automatically packs texture for a libgdx game

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.eowise:gradle-packer-plugin:'
	}
	dependencies {
		implementation("com.github.eowise:gradle-packer-plugin:")
	}
	<dependency>
	    <groupId>com.github.eowise</groupId>
	    <artifactId>gradle-packer-plugin</artifactId>
	    <version></version>
	</dependency>

                            
    libraryDependencies += "com.github.eowise" % "gradle-packer-plugin" % ""
        
        

                            
    :dependencies [[com.github.eowise/gradle-packer-plugin ""]]
        
        

Readme


gradle-packer-plugin

A Gradle plugin witch automatically packs texture for a libgdx game, using libgdx texture packer. Before packing, the plugin can do some actions on the resources provided, such as :

  • Resize images for variants
  • Convert SVG to PNG images

Install

buildscript {
  repositories {
    jCenter()
  }

  dependencies {
    classpath 'com.eowise:packer:0.7.3'
  }
}

apply plugin: 'packer'

Usage

A very basic scenario :

task packs(type: com.eowise.packer.Packer) {
  resourcesInputPath 'path/to/resources'
  atlasesOutputPath 'path/to/atlases'
}

This task will do the folowing actions :

  1. Convert all SVGs to PNGs in the 'path/to/resources' tree
  2. Copy all PNGs do a working directory
  3. Copy all file named 'pack.json' from the resouces path to the working directory
  4. Call the libgdx texture packer to packs the textures from the working directory into the 'path/to/atlases' directory (generally android assets directory)

Resolutions

You may want to add several resolutions :

task packs(type: com.eowise.packer.Packer) {
  resourcesInputPath 'path/to/resources'
  atlasesOutputPath 'path/to/packs'

  resolutions {
    add resolution(name: 'xhdpi')
    add resolution(name: 'hdpi', ratio: 0.75)
    add resolution(name: 'mdpi', ratio: 0.5)
    add resolution(name: 'ldpi', ratio: 0.375)
  }
}

All imput iamges will be resized according given ratio.

Atlases

You can also pack several atlases :

task packs(type: com.eowise.packer.Packer) {
  resourcesInputPath 'path/to/resources'
  atlasesOutputPath 'path/to/packs'

  atlases {
    add atlas(name: 'MainMenu')
    add atlas(name: 'Game')
    add atlas(name: 'Options')
  }
}

Workflow

  1. Convert all SVGs in resources paths to PNGs.
  2. (Before resize hook).
  3. Resize all PNGs in resources paths using the ratio specified for each resolution.
  4. (After resize hook).
  5. Copy 'resolutionName.json' from the resources path to the working directory, and rename it to 'pack.json'.
  6. Call the libgdx texture packer to packs the textures into the output directory (generally android assets directory).