auto-crop feature mangles beam sprites

Place to get help with not working mods / modding interface.
Post Reply
Meppi
Inserter
Inserter
Posts: 29
Joined: Thu Apr 07, 2016 2:57 pm
Contact:

auto-crop feature mangles beam sprites

Post by Meppi »

I'm posting this here and not as a bug report since it is not really a problem in the base game right now.

If you created beam sprites with transparency, the auto-crop feature can crop the head, body and tail sprites differently.
This causes the sprites to be misaligned.

Let's look at the following sprites for head, body and tail
beam-crop.png
beam-crop.png (437.05 KiB) Viewed 2627 times
In the top image the transparent part of the sprites is fully transparent (alpha=000) and thus is being cropped automatically.
The sprites have been cropped differently due to the different heights of the non transparent part, causing the misalignment.

In the bottom image the transparent part of the sprites has an alpha=001 to prevent any cropping.
The sprites are aligned correctly.

Workaround:

When creating beam sprites avoid full transparency and use an alpha value of 001 instead.

Edit:
Actual solution:
Add

Code: Select all

flags = { "no-crop" }
to the animation definition
Last edited by Meppi on Thu Oct 05, 2017 7:34 pm, edited 1 time in total.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: auto-crop feature mangles beam sprites

Post by eradicator »

Can you post the code+sprite sheet you used to produce this example? I've never modded beams before but i get the feeling you're just defining the beam parts wrong in the prototype (It looks like you define the beam segments only half as high as they should be). And making the sprites essentially 80% larger than they should be by adding non-transparent background sounds like the wrong approach.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Meppi
Inserter
Inserter
Posts: 29
Joined: Thu Apr 07, 2016 2:57 pm
Contact:

Re: auto-crop feature mangles beam sprites

Post by Meppi »

I reused the code and image dimensions of the destroyer-robot's beam and just changed the images and frame count.
laser-turret-prototype
You can test the different sprites by replacing A00.png with A01.png
The only difference is the alpha channel. A01 works, A00 doesn't.
You can also check the sprite atlas ingame with F3. You can find them somewhere at the bottom of Atlas 1 and see how they are cropped.
Attachments
Beam_Bug_0.0.1.zip
(3.53 KiB) Downloaded 95 times

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: auto-crop feature mangles beam sprites

Post by eradicator »

EDIT:

OK. Finally managed to reproduce.
A) Your text files have some weird formatting issues. Factorio seems to be only able to read them while they're inside a zip file. If i unzip them i have to first recode them in my text editor or Factorio complectely ignores them. You might want to post a bug report about that if you can reproduce.

B) The issue you're having is angle-dependant. When the turrents shoot horizontal from left-to-right the transparent versions look fine. When they shoot horizontal from right-to-left the odd rendering you described happens.

Trying to think of a fix for this...

EDIT2:

Ok. I found the "fix".
The problem is that factorio sets the rotation center of each part of the beam to the center of the sprite after it internally trimms off the transparent borders. So the rotation center for your tail+head end up in the middle of the "pip" instead of on the crossing where you want it. When shooting left-to-right the sprite is unrotated so even your original sprites look fine. So the correct workaround is to create each frame so that it has it's rotational center on its sprite center. (Removing the transparency like you did happens to satisfy that condition). Imho this is a bug tho (for which you may want to write yet another bug report :P) because modders shouldn't have to care about how factorio internally optimizes sprite sizes.

Here's a working example for your pixel-line-beam that demonstrates the centering mechanism. I've added some black pixels to shift the "center" back onto the beam. The body part can be used unmodified:
beam-tail-A99.png
beam-tail-A99.png (201 Bytes) Viewed 2542 times
beam-head-A99.png
beam-head-A99.png (201 Bytes) Viewed 2542 times
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Meppi
Inserter
Inserter
Posts: 29
Joined: Thu Apr 07, 2016 2:57 pm
Contact:

Re: auto-crop feature mangles beam sprites

Post by Meppi »

eradicator wrote:Your text files have some weird formatting issues. Factorio seems to be only able to read them while they're inside a zip file.
I'm on Linux, so the file uses Unix newline LF instead of CRLF. That might be the problem. I guess that factorio's internal decompression handles it correctly.
eradicator wrote:So the correct workaround is to create each frame so that it has it's rotational center on its sprite center.
The problem here is that you don't know where the sprite center is gonna be after cropping, unless you pay attention to the alpha channel.
eradicator wrote:I've added some black pixels to shift the "center" back onto the beam. The body part can be used unmodified:
That's essentially what i did with the alpha channel. I just used an 'invisible color' instead of black. And i filled the whole image because i didn't care about the few dozen pixels, the cropping would save.
eradicator wrote:Imho this is a bug tho (for which you may want to write yet another bug report :P)
I agree, i just thought that it's such a minor thing and it's not a problem in the base game.
I'm gonna file a bug report anyway, it might come up in the future, when they eventually implement beam lasers. ;)

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: auto-crop feature mangles beam sprites

Post by eradicator »

Meppi wrote:I'm on Linux, so the file uses Unix newline LF instead of CRLF. That might be the problem. I guess that factorio's internal decompression handles it correctly.
Hm. Line breaks i didn't think of. The thing that "made your files work" after being extracted here was just open them in Notepad2 and do Encoding->ASCII. Which should essentially be a null-operation. And NP2 handles line breaks just fine. And even then it shouldn't make a difference between zipped/folder. I even wasted half an hour on trying it with a complete vanilla factorio. So...i really have no fucking clue what exactly is broken there. (I'm on Windows as you might have guessed).
Meppi wrote:I agree, i just thought that it's such a minor thing and it's not a problem in the base game.
All the bugs left at this point are minor, and many of them only affect mods. I guess because of the natural symmetry of "beams" it doesn't usually matter. Your example was just "weird" because the rotation center was shifted so far outside. If you condiser tripple laser walls (death-world-style) you can easily have 100 turrents with 10-20 copies of the body sprite each though. So "a few pixels" gets kinda big i guess? But i generally care so much about cropping that i do it myself in the first place...

I wonder what the center is though if you have an animated beam with several frames. I sure hope it takes the average center of all frames and not of each frame.

Be sure to link this post in the bug report ;)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”