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
buildscript {
repositories {
jCenter()
}
dependencies {
classpath 'com.eowise:packer:0.7.3'
}
}
apply plugin: 'packer'
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 :
- Convert all SVGs to PNGs in the 'path/to/resources' tree
- Copy all PNGs do a working directory
- Copy all file named 'pack.json' from the resouces path to the working directory
- Call the libgdx texture packer to packs the textures from the working directory into the 'path/to/atlases' directory (generally android assets directory)
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.
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')
}
}
- Convert all SVGs in resources paths to PNGs.
- (Before resize hook).
- Resize all PNGs in resources paths using the ratio specified for each resolution.
- (After resize hook).
- Copy 'resolutionName.json' from the resources path to the working directory, and rename it to 'pack.json'.
- Call the libgdx texture packer to packs the textures into the output directory (generally android assets directory).