I got strange effect when use map tiles with transparency. It is seems like thin border around it. I uploaded pictures:
First. This tile:
Same code, but this tile:
You can see: where new tile is, no ugly lines more.
I decided to make a map with tile overlay and I use tile map 24 x 24.
I need this transparency for unification of tiles by size. I can make code for work with tiles with different sizes, but it worst way in my case.
Thanks for attention!
There are 2 possible reasons for such thin lines. It probably is issue AD 1 for you, but if my explanation doesn’t help – please upload a testcase to reproduce the problem, so that I can tell for sure
Lack of alpha bleeding on tileset image. See Alpha Bleeding | Manual | Castle Game Engine about what is “alpha bleeding”. Long story short, you want to have some spacing between tileset images (both CGE and Tiled support such spacing) and fill this space with RGBA colors from adjacent pixels.
Our castle-view-image has a menu option to add alpha bleeding (but you need to make sure there’s already some space between tiles for it).
As a quick workaround, you can also activate SmoothScalingSafeBorder, but this is not a recommended way – it necessarily shifts some pixels.
Note that this problem is only possible if you use SmoothScaling=true.
I think I see, with SmoothScaling pixels look better
But i read in manual what “The algorithm implemented here, for now, is really slow (but also really correct)”.
Is this important for a small 2D picture?
For now i use .Url to load map tile everytime.
But, because i need to change tiles sometimes, I must download all of they into the program with AlphaBleed option at game start and after that set they as i need, yes?
For example, i can create array of TCastleImageTransform and load tiles with AlphaBleed into it. And after that I will use images from there. Right?
Sorry, I must admit I don’t understand the question 100%. Your normal flow would be:
Create several images with map tileset (like terrain) or map objects (like monsters).
Drag-n-drop them into castle-view-image (or any other tool capable of fixing the issue, I’ve made myself a command-line utility just for this one specific task as I run into this issue for every asset in my game), run “fix alpha bleeding” on them.
Drop them into data folder of your game.
Forget about the problem forever Unless you need to update your tilesets, just repeat the procedure then.
I believe you already have seen Castle Game Engine: CastleImages: Class TCastleImage — so the idea is that while indeed you can run this on some images when loading them and it will give the desired effect, you don’t have to - it will reduce performance, even if it’s just during the loading process.
What I’ve meant is that you can simply run it once on the image and inside of data folder store “already fixed images”. This way you don’t need to do any additional processing when your game runs. You can do this through castle-view-image tool, or you can do this through any other tool that can “fix alpha bleed”. I’ve made myself a command-line tool alphableeder · master · EugeneLoza / Shifted Image Control · GitLab so I just drag-n-drop all the files to be processed on it, and in a few seconds get the result.