[Tutorial] sprites.png sizing

Discussion about Mods for Prison Architect

Moderator: NBJeff

User avatar
Ghost314
level1
level1
Posts: 24
Joined: Thu Dec 24, 2015 9:23 pm

Re: [Tutorial] sprites.png sizing

Postby Ghost314 » Thu Dec 24, 2015 9:50 pm

Puman wrote:These are the rules you should follow when creating a sprites.png file if you want it to play better together with other mods:
keep it as small as possible
use sides that are 32, 64, 128, 256, 512, 1024 or 2048 pixels wide


Is there a particular reason to use powers of 2? I just checked the "Stock Sprite Fix" mod I downloaded on steam and they're using a sprites.png size of 896x896 which is a multiple of 32, but not a power of 2.
User avatar
hoosdatGuy
level1
level1
Posts: 10
Joined: Tue Oct 21, 2014 1:56 am

Re: [Tutorial] sprites.png sizing

Postby hoosdatGuy » Fri Feb 05, 2016 12:43 am

Mercury002 wrote:The money laundering mod is terribly inefficient, there are gaps everywhere.

I'm sorry for that, I was never aware of this problem. Besides, it was my very first mod. The moment I read this I went and optimized the spritesheet though it's been quite a while since this was posted...
Anyways it's down from 320x384 to 320x256, with only one (unavoidable) 64x64 empty space, hopefully it should work with a larger quantity of mods now.

As for the above question, I would say that keeping it as small as possible is more important than having sides that are powers of 2, for example if you're in a 256x256 box and your mod could fit in a 192x192 area, you could fit seven 64x64 spritesheets in the leftover space, but if you make it 256x256 you're wasting that space. Or in crappy ASCII graphics:
xxxo > xxxx
xxxo > xxxx
xxxo > xxxx
oooo > xxxx
murgh
level2
level2
Posts: 228
Joined: Sat Jan 30, 2016 11:52 am

Re: [Tutorial] sprites.png sizing

Postby murgh » Sun Feb 14, 2016 10:20 pm

Nice tutorial! It helped me expand the mods I use and want to use a lot.
I cramped everything I wanted from something like 27 mods into two sprite images of 1024x1024 with only one tile of 32x32 space left free!
And the best thing after a weekend of fiddling around with it is that everything works as intended. 8)
You just need to pay attention to the positioning of all the sprites.
Think this sounds too good to be true? Have a look: http://i.imgur.com/cUWhanJ.jpg

Btw these two mods I made are for personal testing only. I see no need to release them to public, since I can't be bothered with tons of questions/bugreports/requests, nor asking for permission from more than 20 authors... And I don't use Steam so there is no way for me to upload it there anyway. It just shows that it is possible to combine lot's of stuff if you want to spend some time on it.

But one question arises, why can't the game engine itself fix what took me a weekend to puzzle together? :s
Finally I can have a prison basketball, several different workshops, gardening stuff and much much more all together in one game.
Something that was impossible before, even by trying to fit all separate mods in different order.... I dare you to try it yourself and load all the mods you recognize from the screenshot - you will fail miserably. :|

The game engine should strip every single sprite from its given canvas and throw them onto the big canvas before the game starts, instead of trying to match all the different canvases from the mods sprites.png files onto one big canvas. It makes the difference between lazy programming and proper programming.
Last edited by murgh on Thu Feb 25, 2016 9:43 pm, edited 4 times in total.
murgh
level2
level2
Posts: 228
Joined: Sat Jan 30, 2016 11:52 am

Re: [Tutorial] sprites.png sizing

Postby murgh » Sat Feb 20, 2016 11:25 pm

Puman wrote:All mods together must share a total space of 2048x2048 pixels (this is mentioned in the games debug log). The sprites.png of all mods are packed into this limited space, when the space runs out the next mods will get rather random graphics.


Playing around with large sprites.png files I noticed the maximum amount you can safely load is two images of 1024x1024 (which is also the maximum size allowed for a sprites.png as mentioned on page 1).
If you add a third sprites file, it will start to overwrite the first one, starting in topleft corner. Examples:

Here is a snip from debug.txt when loading three sprites with sizes 1024x1024, 1024x1024, 512x512:

Code: Select all

Loading user sprite images for path: /mods_Combi_2/data/sprites.png
Loading user sprite images for path: /mods_Combi_1/data/sprites.png
Loading user sprite images for path: /mods_Combi_3/data/sprites.png
~
PackRectangles(2048, 2048) packing 3 rectangles
Packing:
WorldRenderer::LoadUserSpriteImages Compositing image /mods_Combi_1/data/sprites.png to 2048, 1024
WorldRenderer::LoadUserSpriteImages Compositing image /mods_Combi_2/data/sprites.png to 3072, 1024
WorldRenderer::LoadUserSpriteImages Compositing image /mods_Combi_3/data/sprites.png to 2048, 1536
Created FrameBuffer of size 64 x 64 in 1ms
Object spritebank composite took 3212ms
Warning: Loading a very high res image (2688x128)
Warning: mipmaps requested for non-power-of-two image (2688x128), will break on OpenGL ES


Notice the (x/y positions?) where WorldRenderer puts these together.
When in game this will result in the Combi_3 sprites.png (512x512) overwriting the top left corner of the first sprites.png (Combi_1) canvas.

To have something to compare, here is a snip from debug.txt when loading three sprites with sizes 1024x1024, 1024x1024, 256x256:

Code: Select all

Loading user sprite images for path: /mods_Combi_2/data/sprites.png
Loading user sprite images for path: /mods_Combi_1/data/sprites.png
Loading user sprite images for path: /mods_Combi_3/data/sprites.png
~
PackRectangles(2048, 2048) packing 3 rectangles
Packing:
WorldRenderer::LoadUserSpriteImages Compositing image /mods_Combi_1/data/sprites.png to 2048, 1024
WorldRenderer::LoadUserSpriteImages Compositing image /mods_Combi_2/data/sprites.png to 3072, 1024
WorldRenderer::LoadUserSpriteImages Compositing image /mods_Combi_3/data/sprites.png to 2048, 1792
Created FrameBuffer of size 64 x 64 in 0ms
Object spritebank composite took 3336ms
Warning: Loading a very high res image (2688x128)
Warning: mipmaps requested for non-power-of-two image (2688x128), will break on OpenGL ES


And again, in this example the sprites canvas from Combi_3 will overwrite top left 256x256 part of the first sprites.png canvas (Combi_1).
In the games mods menu these mods were sorted in this order:
Combi_2
Combi_1
Combi_3
(but not loaded that way by worldrenderer?)

I'm not sure if it was intended to have space for 'only' two 1024x1024px sprite for modding available. It seems a rather small area, and in fact is way smaller than the example drawing from ts. If the max size would be 2048x2048 then I should have been able to properly load 4 images of 1024x1024...yet a third one of a few pixels already starts to overwrite things :?

Image

You can test this yourself by loading these testmods (make sure you have all other mods disabled or saved into a different modmap) https://www.sendspace.com/file/3o8q9b
murgh
level2
level2
Posts: 228
Joined: Sat Jan 30, 2016 11:52 am

Re: [Tutorial] sprites.png sizing

Postby murgh » Mon Mar 28, 2016 8:37 pm

By coincidence I have just discovered that it's possible to define your custom sprites using the objects.png, people.png and special-entities.png files by using negative values for x / y positions.
You can make a mod without using your own sprites.png file and still use any object on one of these images. And the good thing is, you can ALSO reach those objects if you DO have a custom sprites.png in your mod. A picture explains more than a wall of text here, so I'll just give you a wall of sprites with some x/y coordinate examples to play around with. Here you go, have fun modding!
Image

This means for instance that the sprites.png canvas size from my booths mod can be reduced by quite a bit: currently it holds all standard sprites for workmen (4 rows of 4 sprites) and guards (4 rows of 4 sprites) as well the new ones (also 8 rows of 4 sprites). But now I just found out that the standard sprites could be reached just to the left of the canvas of our modsprite area, saving tons of space for other mods!

edit: hmm something in that picture is wrong, since I noticed before that the maximum space used for mods can only be 2x 1024x1024px and those two are side by side. But the grey field in the picture is 2048x2048px... So the grey field should be divided by half horizontally, and we have some mysterious emptiness below our modsprites all the sudden :o Also, where is tileset.png? It should be floating around somewhere as well, but some random x/y tests I did only showed up with empty black space or some vertical black lines.
murgh
level2
level2
Posts: 228
Joined: Sat Jan 30, 2016 11:52 am

Re: [Tutorial] sprites.png sizing

Postby murgh » Tue Apr 05, 2016 11:54 pm

I forgot to make a side note for the above example. The x/y coordinates work fine if you only use one mod, which will by default start at the top left corner. However, if several mods are loaded and the mod you made also contains a custom sprites.png, it seems that those x/y values start to change and you have to recalculate the exact positions...but not always. :shock: :? Weird stuff happening, pff. This should not be a problem when you have full control over your mods, but will be a problem in other situations. Bummer.

As a side effect of this I saw it should be possible to borrow sprites from your neighbour mod as well. So if you have two 1024x1024 mods then you should be able to define a sprite from the second mods sprites.png in the first mods materials.txt if you just find the exact x/y coordinate for it. To make that somewhat easier, define an object of width/height 8x8 or bigger and mess around with the x/y values. Soon you will recognize an area you just hit when you lay that sprite down on the open field, and when you look it up in the mentioned png files you can calculate the positions you want to use.
User avatar
dsdude123
level2
level2
Posts: 75
Joined: Tue May 27, 2014 2:40 am
Location: Seattle,WA
Contact:

Re: [Tutorial] sprites.png sizing

Postby dsdude123 » Wed Jul 27, 2016 3:12 pm

This bug/limitation has been patched in Update 8.

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 1 guest