Pattern-Script
Pattern-Script copied to clipboard
Add crop transform
This is a first attempt at a crop transform (#39). I'm pretty sure it needs some work. The code is pretty messy, and I'm not 100% convinced it correctly deals with all possible cases. I also still don't know what the best name for this would be. Truncate, crop, trim, clip all seem reasonable.
And finally, it would be nice if there were a way to not crop a sprite down and right (which sort of happens because those parts of the sprite just get overdrawn). Would it make sense to draw the grid in multiple passes, one per collision layer? This would probably have some other awkward effects for pseudo-3D games. Maybe to do this properly, we'd need some kind of separator syntax in the collision layer list, and then the engine makes a separate rendering pass for each of the segments defined this way.
In any case, I figured I'd throw something together, so you've got something to go off of. This isn't really meant to be merged as is.
I had a look at the code. If I understand well, it provides a way to cut the offset sprite along one (or all) of the sides of the cell? I think I would prefer a way to remove some given number of lines of pixels on a given edge of the sprite, independently of the sprite's offset. To crop along the cell's border you would need to keep track of the sprite's offset and size, but I think this is a more general feature and a simpler one to implement. Also, because I'm working on a sprite editor and the functions to resize a sprite are already written :-D
Oh yeah, you're right, a transform to simply shave off a given number of pixels sounds a lot simpler. 😅
Reworked the PR to implement your suggested transform instead. Also renamed it to trim because with the new behaviour that seems like the clearest name.
Thanks! I keep the PR opened as a reminder. I'm currently working on a feature that requires to change a little bit how sprite transforms are applied, and also I have already done some code to resize sprites in that feature. So, I will integrate this new transform directly with the new feature.