Why does Prison Architect hate my sprites?

Discussion about Mods for Prison Architect

Moderator: NBJeff

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

Why does Prison Architect hate my sprites?

Postby Ghost314 » Fri Dec 25, 2015 4:14 am

I've been working on a mod to try and make toilets automatically switch from a toilet bowl sprite to an 'outhouse' sprite when placed outdoors, just like lights switch between a light bulb and a lamp type thing.

Before I move on to the more complex part, I wanted to start with getting a new 'outhouse' object to appear on the objects screen, and figure out how to properly define it's sprite so that this new object will look right when placed in-game. For some reason, I just can't seem to get Prison Architect to load the sprites I want to use correctly. In the course of troubleshooting, I simplified my mod to the following:

materials.txt

Code: Select all

BEGIN Object
   Name             Outhouse
   ConstructionTime    3.00000
   MoveSpeedFactor       0.500000
   Toughness          15.0000
   Price             -100
   RenderDepth          1
   NumSlots          1
   AttachToWall       true
   Group             StaticObject
   BlockedBy          Wall
   BlockedBy          StaticObject
   BlockedBy          UtilityStation
   MadeOf             Composite
   Properties          StaticObject
   BEGIN Sprite
      x 0
      y 0
      w 1
      h 2
      RotateType 3
   END
END


sprites.png
Image

This works as I expect, and in-game I see the following when placing my 'outhouse' in the 4 different rotations, side-by-side.
Image

I then copy-pasted the sprites I actually wanted to use, into the working sprites.png, and left everything else the same.
Image

This fails, and when placed in-game in the same manner as for the working sprites, I get this.
Image

Can someone enlighten me as to how Prison Architect, managed to pull that out of my sprites.png file? Naturally, I didn't expect it to look right since my outhouse sprites don't perfectly line up with the nice 32x32 squares, but there's no way it should look like it does in my screenshot. I should also state for the record, that I made no changes to the overall pixel size of sprites.png, in both cases it was 128x96, and I can't for the life of me, figure out the relevant difference between the sprites.png with my outhouse sprites in it, and the one with squares and transparency.
Linkero
level0
Posts: 2
Joined: Sun Dec 20, 2015 12:49 am

Re: Why does Prison Architect hate my sprites?

Postby Linkero » Fri Dec 25, 2015 5:39 pm

I had this happen to me recently. Im not sure the exact cause, but the two culprits for me were the rotate type and attaching to walls. For you, I feel your issue is probably the rotate type. I'm not near my computer currently, but I believe for rotate type 3, you need to define all 3 sprite locations in your object. Again, not 100% sure but I hope this helps you figure it out. When I'm near computer I'll do a bit more digging for ya

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

Re: Why does Prison Architect hate my sprites?

Postby Ghost314 » Sat Dec 26, 2015 1:57 am

Linkero wrote:I had this happen to me recently. Im not sure the exact cause, but the two culprits for me were the rotate type and attaching to walls. For you, I feel your issue is probably the rotate type. I'm not near my computer currently, but I believe for rotate type 3, you need to define all 3 sprite locations in your object. Again, not 100% sure but I hope this helps you figure it out. When I'm near computer I'll do a bit more digging for ya

Happy holidays!


To me, the incomprehensible part is that the exact same materials.txt code works just fine when the file contains a bunch of ugly squares, it's only when I paste in the sprites I want to use that it has issues. I just switched my computer back on after leaving it off to visit some family, so maybe the reboot will help, if not, I'm sorely tempted to start re-painting my outhouse sprites into the ugly squares file, and see at what point it suddenly stops working.
User avatar
Ghost314
level1
level1
Posts: 24
Joined: Thu Dec 24, 2015 9:23 pm

Re: Why does Prison Architect hate my sprites?

Postby Ghost314 » Sat Dec 26, 2015 4:26 am

My experimentation has yielded some interesting results. I started to copy paste my sprite into the image bit by bit, and sure enough, there came a point where putting in any more pixels from my sprite into the sprites.png file would cause in-game issues. It didn't much matter where I drew these pixels, as long as they were of the same color, it would cause the loading of the image in-game to fail. Furthermore, the failure point was different for different colored pixels, for instance I was able to draw in a bunch of 'light green' pixels from my sprites, then the image would start to fail for any additional light green pixels I tried to insert, but it would let me draw in a few more black pixels and dark green pixels, until I hit a stopping point for those too.

I was going to re-color the background from the various different colored squares to white (for clarity's sake) and upload the results here, but then I discovered that recoloring the off-screen portion of sprites.png white, allowed me to color in more of the pixels for my sprite before it started to fail again.

Experimenting further, I expanded the size of my sprites.png from 128x96 to 256x256 and colored all the extra pixels white. This had a negative effect and the game failed to load the same image that worked in the 128x96 size. So I tried the other direction and truncated my sprites.png file to 128x70 (70 is the actual height of my outhouse sprites) and I was able to color in a few more, but not quite all of the pixels for my outhouse sprites. So I cut down the width as well, to 114 (the actual width of my outhouse sprites) and I was able to input my entire sprite sheet. Ironically, the only reason I didn't do this from the start was because I thought I would be doing Prison Architect a favor if I made my sprites.png match up nicely with their internal 32 pixel coordinate system, instead of using a non-standard size like 114x70.

So now my sprites.png looks like this:
Image

And when placed in-game I get this:
Image

As expected, they don't look quite right since they don't match up with the 32 pixel coordinate system, which brings me to problem number 2, which I hope will be a rather straightforward answer. When I try to set my height in materials.txt to 2.9 it seems to be truncating it to 2. I checked over the materials.txt for the "Stock Sprite Fix" mod and it looks like all sprites have been defined with integers for the x,y,w,h properties. Is this a general requirement of those properties? I noticed some markers were being defined using decimals, so I had gotten the impression that I could use decimals for the sprite definition as well, but if not then that's a restriction I can work with.
User avatar
a__gun
level3
level3
Posts: 281
Joined: Wed Sep 26, 2012 4:16 pm
Location: UK

Re: Why does Prison Architect hate my sprites?

Postby a__gun » Sat Dec 26, 2015 11:17 am

Sprite sizes are defined as integers representing multiples of 32px. If your sprite is narrower than this you can either resize it or centre it in a 32px square, leaving gaps between your sprites where needed.

From your testing, it sounds to me like the file size is what's causing your odd behaviour - are you saving with an unusual format or something..?
User avatar
Ghost314
level1
level1
Posts: 24
Joined: Thu Dec 24, 2015 9:23 pm

Re: Why does Prison Architect hate my sprites?

Postby Ghost314 » Sat Dec 26, 2015 2:38 pm

a__gun wrote:From your testing, it sounds to me like the file size is what's causing your odd behaviour - are you saving with an unusual format or something..?


I've been saving it as a .png file, which is what the "Stock Sprite Fix" mod uses, and the overall file size for my sprites.png is lower in all cases. Upon closer inspection however, it looks like the malfunctioning sprites.png files are using a bit depth of 8, while the working ones have a bit depth of 32.
User avatar
Brento666
level3
level3
Posts: 290
Joined: Wed Sep 02, 2015 9:23 pm

Re: Why does Prison Architect hate my sprites?

Postby Brento666 » Sat Dec 26, 2015 11:12 pm

Ghost314 wrote:
a__gun wrote:From your testing, it sounds to me like the file size is what's causing your odd behaviour - are you saving with an unusual format or something..?


I've been saving it as a .png file, which is what the "Stock Sprite Fix" mod uses, and the overall file size for my sprites.png is lower in all cases. Upon closer inspection however, it looks like the malfunctioning sprites.png files are using a bit depth of 8, while the working ones have a bit depth of 32.

Reading up on your experimentation; It does sound like your image-tool is saving in an incompatible png-format.. sometimes :S
-What program are you using? (never had these issues using Gimp here)
User avatar
Ghost314
level1
level1
Posts: 24
Joined: Thu Dec 24, 2015 9:23 pm

Re: Why does Prison Architect hate my sprites?

Postby Ghost314 » Mon Dec 28, 2015 12:02 am

I've been using paint.net, but I am familiar with Gimp as well and have used it in the past. Still, if the issue is the bit depth, then this would be the first I've heard about Prison Architect supporting only a certain bit depth. Will probably run a few more tests later to confirm, as it would be a good thing to know and record somewhere if it isn't already.
User avatar
Landuros
level1
level1
Posts: 10
Joined: Sat Dec 12, 2015 10:38 am

Re: Why does Prison Architect hate my sprites?

Postby Landuros » Mon Dec 28, 2015 1:02 am

I can spot a very simple mistake... I don't know if you have fixed it, but I'll post this anyways. Your original sprites.png is fine, because it loads correctly. As soon as you pasted the toilet blocks in, you got a problem. The problem is that your toilet sprites are too big. They don't fit into your original toilet sprites. You have incorrectly defined the size of your toilet block sprites, which is why the game cuts off your sprites. Your currently code tells the game your toilet blocks are 32x64. However, you can see that they are slightly bigger than that.

I've edited your code by changing the w and h variables in the sprite defs.

Code: Select all

BEGIN Object
   Name             Outhouse
   ConstructionTime    3.00000
   MoveSpeedFactor       0.500000
   Toughness          15.0000
   Price             -100
   RenderDepth          1
   NumSlots          1
   AttachToWall       true
   Group             StaticObject
   BlockedBy          Wall
   BlockedBy          StaticObject
   BlockedBy          UtilityStation
   MadeOf             Composite
   Properties          StaticObject
   BEGIN Sprite
      x 0
      y 0
      w 2
      h 3
      RotateType 3
   END
END


Also, the reason why your first problem (the glitched sprite) happened is because you didn't define the height of the object... I think.
User avatar
Ghost314
level1
level1
Posts: 24
Joined: Thu Dec 24, 2015 9:23 pm

Re: Why does Prison Architect hate my sprites?

Postby Ghost314 » Mon Dec 28, 2015 2:09 am

I ran some more tests, paint.net actually displays a screen that allows you to select a bit depth when saving a new .png file for the first time. Since I didn't even know what bit depth was, I left it on the default setting, which is 'auto-detect', which I can only assume, has paint.net automatically select the optimal bit depth based on the .png image you're trying to save.

I tried switching this setting from 'auto-detect' to '32-bit' and re-saved each of the malfunctioning sprites.png files, and sure enough, they work as expected when saved with a bit depth of 32. I also tried flipping it to 8-bit and re-saved some of the working sprites.png files, and they each failed when saved with a bit depth of 8.

At this point I'm convinced the issue is the bit depth, the fact that is was set to auto-detect explains all of the strange behavior I've seen, including the curious case of seeing it work/not work based on how I changed the colors of pixels, or the size of the image. In each case paint.net was simply saving with a different bit depth based on the image contents. So to ensure my sprites are rendered as expected, I need to force paint.net to save my .png files with a bit depth of 32.

I can spot a very simple mistake... I don't know if you have fixed it, but I'll post this anyways...


I am aware of the sizing issue, originally I had planned to define my width and height as w=1.1875, h=2.1875 because I had assumed after seeing decimals in marker definitions, that I could put decimals in sprite definitions, I have since learned that this is not the case. At this point I consider the fact that it chops off my sprites to be expected, it was the one that displayed as a garbled mess, even after switching my width and height to nice whole numbers, that confused me.

P.S. you may want to consider including the knowledge gained from this thread in your post on sprite tips, since the 'auto-detect' bit depth setting is the default setting for paint.net, anyone who uses paint.net for editing sprites could potentially hit this problem.
User avatar
Landuros
level1
level1
Posts: 10
Joined: Sat Dec 12, 2015 10:38 am

Re: Why does Prison Architect hate my sprites?

Postby Landuros » Mon Dec 28, 2015 3:31 am

Glad to see that you have figured out how to solve your problem. Thanks for the advice, I will change it accordingly.

Have fun gaming!
User avatar
Brento666
level3
level3
Posts: 290
Joined: Wed Sep 02, 2015 9:23 pm

Re: Why does Prison Architect hate my sprites?

Postby Brento666 » Mon Dec 28, 2015 5:23 pm

Landuros wrote:...
Also, the reason why your first problem (the glitched sprite) happened is because you didn't define the height of the object... I think.

Hi Landorus,
Setting no height makes it default to 1. Same for width.
Having sprites that don't fit in defined areas won't glitch your sprites, it's just going to chop off the sprite at the defined edges.

@Ghost314: Great you found the culprit!! Looking forward to yor out-house toilets :D

Fyi: The Gimp will default to 32-bit colors, but can be asked to convert to 8-bit depth, but there it has to be done explicitly...
(I sometimes use this to get file-sizes down on my screenshots)

Return to “Modding”

Who is online

Users browsing this forum: No registered users and 16 guests