There appears to be a rendering bug with sprites. It appears as though the sprite renderer is sampling pixels from the cell next to it. This is exhibited in all of the following documentation samples:
This looks to me like just a poorly designed spritesheet. The line you are seeing and qualify asā a bugā is simply the feets from the sprite above. Say you would change the size to 65px instead of 64px (it would of course mess everything horizontally). But the line is gone. So this is really just when designing your spritesheet. Itās important you create a grid and when working with pixels (obviously) remain consistent and precise (and leave at least 1px, possibly 2px to play it safe for resize/rescale, transparent on each cell). Else, I donāt see anything wrong with the sprite manager.
I hope this helps and reassures you towards your project andā¦meanwhile, have a great day
Edit: Since I donāt like answering by making just assumptions I quickly double-checked by opening the spritesheet in PSD. Turns out I was right (check out the rulers set at 64px in this SS below from PSD on the original spritesheet).
I created a repro PG that exhibits the bug I described earlier today.
Here is a screenshot showing the source image in Aseprite and the PG. The image is 224 x 96 pixels, and the tile size is 32 pixels. I drew lines one pixel outside the cell of each of the three colored circles. When rendered by the BJS sprite class, you can see these lines even though they should not be part of the sprite cell.
In essence, yes. Should be. In practiceā¦ Honestly, I also have the same issue with i.e. svg (non-related to BJS). When I draw a circle at zero pixel on the canvas and then import my svg (even in photoshop) I eventually get a bit of it thatās cropped. Reason why I always leave at least 1px transparent.
You can also see it flickering when zooming in or out. Eventually the line would disappear. I believe itās because there must be some rounding operation made. Now, Iām shit with maths. May be this can be improved, ensuring it will never round higher than the limit. But that might also mean that the last bit could be cropped 1px (at least from my understanding).
Anyway, the Team will likely have a look at it today and answer. For whatever answer there is, I think Iām gonna stick with my way of leaving 1px transparent. As a designer, this sort of thing doesnāt really strike me . I just find a way to play it safe (but I do understand that it can strike a dev or eng sinceā¦ as you say, this is just not entirely correct (at least in theory )
The problem comes from the fact that the default blending for sprites is ācombineā. If your sprite is alpha-tested only and you donāt want to blend with the screen, you can disable alpha blending (see line 14):
You can check that turning alpha blending for the shader material makes the artifacts appear:
This has me confused. Not speaking about the shader, if I use pixelperfect and bilinear sampling with alpha disable, I still have the lines. Not to mention I lost the alpha of course.
Though, Iām not even sure why I bother. As said, I always leave at least 1px transparent when working with the alpha. This way, thereās absolutely zero issue, so I really donāt see the pointā¦ I must be missing something?!
Good morning everyone. Thanks for chiming in on this issue.
The original point of my thread here is that I was expecting to have 3 separate sprites rendered on screen, but WITHOUT the lines surrounding them because they are NOT part of the sprite cell. I created the sprite sheet very specifically to show that the inner 3 cells only have filled circles, and the cells adjacent to them have content in them (lines in this case, and they very intentionally are butted up against the cells that I intended to render).
It should not matter if the cells I marked as āempty cellā actually have any content in them. The problem is if the they do have content that is directly adjacent to the sprite cells in the sprite sheet, they are getting incorrectly rendered. I should only see filled circles on the screen, no lines. Does that make things clearer?
It requires changes to the core library so I have to create a draft pull request. It will trigger a creation of a snapshot build. Once itās ready, Iāll send you the link to the snapshot.
Wait a minuteā¦ or 45 while it builds the snapshot
Thanks Roland. Iām at work for the day so will have to wait till this evening to try it out. I very much appreciate your help. Also thanks to everyone else on this thread.
I had to introduce a new property called pixelPerfect to the cellSize options. I need to disable sprite instancing in the constructor of the SpriteManager. This is of of course subject to change. This is just a proposal so actually every change is subject to change
Modifying the pixelPerfect property after creating the SpriteManager does not turn on sprite instancing for now.
You can disable sprite instancing by doing engine._features.supportSpriteInstancing = false;:
The offset (0.01 - default value if you donāt pass a parameter for the 6th parameter of SpriteManager constructor) seems to help, although I guess the right value to use will depend on the texture/sprite sizesā¦
Thanks, I traced back the source where it is read from, however it would be more convenient to turn it of just for a single SpriteManager instance.
Would you please have a look at the draft PR and express your thoughts? I must confess, I didnāt really think through the condition when to apply a positive or negative epsilon so that part might be not exactly correct.
Another thing is how are we gonna deal with the pixelPerfect setter.
Hmm, when you view them in different browser tabs and flip back and forth, you can also see that the pixels from the cell you do want to render is being possibly cropped (looks like its being shrunk).