Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Asset Packing

A topic by Ada18980 created Jun 25, 2024 Views: 374
Viewing posts 1 to 1
(3 edits)

Hi! This tutorial covers preloading asset textures, which is necessary if you want the game to properly load assets! There are two ways to preload:

  1. using a texture packer (such as TexturePacker) to create a texture atlas, and then loading the atlas
  2. Loading each sprite manually as part of a list

1) Using a texturepacker

This one is relatively simple in terms of steps, but requires that you figure out a texture packing solution. I use texturepacker mainly out of habit, but I believe there are many free options as well. The game uses pixi.js, so make sure your packer is outputting .json atlases that are compatible with pixi.js.

Once youve generated your atlas (make sure the root folder is set properly to the Models/ folder, so that filenames start with Models/) you can load the atlas:

// Note: Requires Kinky Dungeon 5.1.7 or later
PIXI.Assets.load({
   src: "TextureAtlas/livingCageAtlas.json",
   loadParser: 'modAtlasLoader'
});

With this method make sure to include the .png and .json produced by the atlas. You can put them in the TextureAtlas folder in the root of your mod zip.

You must also include the original asset files in the “Models/” folder as the game is not smart enough to create blobs for the texture assets yet 😦

2) Loading each sprite manually

For this I use a list to make things easier:

let FileList = [
  "Item.png"
]

for (let dataFile of FileList ) {
PIXI.Texture.fromURL(KDModFiles["Models/" + dataFile], {
  resourceOptions: {
    scale: 0.5 // You can change the scale to reduce the size of the file and improve performance
  }
});
}

The problem with this method is that performance is worse as it also loads a bunch of transparency data. Texturepacker strips the excess area which makes rendering much faster as the engine doesnt have to render empty space. But you don’t need a texturepacker. This works well for assets close to the face as you can crop out most of the image while preserving offset data.

With this method you have to keep your files in the Models/ folder in the root of your zip. You could theoretically put them in Data as well but Models is the established location for them