drawTiles pixel bleeding

There is a bug with drawTiles method: When I use spritesheets and the sprites are packed without any space between them like this one: [img]https://sites.google.com/site/zaphodmech/mech/packed_sheet.jpg[/img] and when I draw tiles with smoothing it look…

Viewing 1 to 11 (11 Total)
drawTiles pixel bleeding

Zaphod

Zaphod
Total Posts: 218
Joined: September 15, 2011

There is a bug with drawTiles method: When I use spritesheets and the sprites are packed without any space between them like this one:

and when I draw tiles with smoothing it looks like this:

(it's not my images, i took them from herehttp://www.nulldesign.de/2011/08/30/nd2d-pixel-bleeding/... . But I think it is clear what is the problem)
Drawing tiles without smoothing doesn't have that problem but quality is terrible.
Maybe there is a way to fix this?

PS: the same problem with drawTriangles method both in flash and cpp. And I think that drawTriangles cannot be fixed.

Tags:
Posted on November 14, 2011 at 10:00 AM

aaulia

aaulia
Total Posts: 48
Joined: November 07, 2011

Re: drawTiles pixel bleeding

Sorry if this turns out to be false, but just a guess, the black "bleeding" is the result of smoothing, since you are using sprite sheet, it means smoothing is done globally against the whole sprite sheet. Now, because your sprite sheet doesn't contain "gap" between the letter, you get "leak" from neighboring letter.

Posted on November 14, 2011 at 11:14 PM

Zaphod

Zaphod
Total Posts: 218
Joined: September 15, 2011

Re: drawTiles pixel bleeding

Thank you for explanation. I didn't think about it. I will keep it in mind in the future

Posted on November 15, 2011 at 12:55 AM

Zaphod

Zaphod
Total Posts: 218
Joined: September 15, 2011

Re: drawTiles pixel bleeding

Hi again. After some time I met again this kind of issue, but without smoothing. It appears only if I set tile rotation or non-integer tile scale.
Is there any solution without changing tilesheet's source bitmapData (inserting gaps)?

Posted on April 26, 2012 at 2:38 PM

Huge

Huge
Total Posts: 548
Joined: October 07, 2011

Re: drawTiles pixel bleeding

Hi,
There are two solutions for this.
1. leave a 1-pixel alpha=0 gap between your letters - this is the preferred solution.
2. shrink your rects by 0.5 pixels in each direction (left,right-top-bottom). This will make your letters thinner, but you will not be blending with adjacent glyphs.

Otherwise, you must be very careful to render 1:1, pixel aligned without rotation.

Hugh

Posted on April 27, 2012 at 12:09 AM

Zaphod

Zaphod
Total Posts: 218
Joined: September 15, 2011

Re: drawTiles pixel bleeding

Thanks, Hugh. But I know about these solutions already. So, it can't be fixed on NME side?

Posted on April 27, 2012 at 12:14 AM

Philippe

Philippe
Total Posts: 261
Joined: September 08, 2011

Re: drawTiles pixel bleeding

@Zaphod: what do you want NME to do automatically?

As the comments indicate in the post you linked to, cutting the tiles has ugly side effects so it's probably better that you decide what to do (like modify the rects yourself when defining the font).

For what is worth TexturePacker offers 2 options: padding with alpha=0 pixels or duplicating edge pixels. Both options will depend on what you need to do.

Posted on April 27, 2012 at 3:12 AM

Zaphod

Zaphod
Total Posts: 218
Joined: September 15, 2011

Re: drawTiles pixel bleeding

@Philippe: I will add 1 pixel gap for it. But I didn't know about this kind of "feature" earlier and just wanted to know about possible solutions

Posted on April 27, 2012 at 3:28 AM

renolc

renolc
Total Posts: 2
Joined: May 02, 2012

Re: drawTiles pixel bleeding

I'm having a similar pixel bleeding issue, but under different circumstances:

I've noticed that when targeting flash, if I use a scale of 4 or more when doing draw tiles, it seems to bleed a little from the surrounding pixels. This was quite noticeable for my test app, because my plan was to use 8x8 sprites and scale them up 4x (retro look ftw).



This is with smoothing off, which is how I plan to keep it. It also doesn't seem to happen if I target cpp. Only flash.

A work around would be to use 16x16 sprites and scale 2x which fixes the issue, but just thought I would bring it up in case it turns out to be a bug.

Posted on May 02, 2012 at 8:23 PM

Huge

Huge
Total Posts: 548
Joined: October 07, 2011

Re: drawTiles pixel bleeding

Hi,
What are you using to draw the tiles with? Bitmaps/copyPixels ?
For bitmaps, you could try offsetting your x + y by 0.5 of a pixel, eg: gfx.drawRect(100.5, 200.5, 32, 32)

Hugh

Posted on May 02, 2012 at 11:29 PM

renolc

renolc
Total Posts: 2
Joined: May 02, 2012

Re: drawTiles pixel bleeding

This is how I'm currently loading and drawing the tiles. I'm probably going to change it so that when targeting flash it uses copy pixels instead since it doesn't seem to perform very well when there are a lot of tiles in the draw list.

Your suggestion worked when I subtracted 0.3 from the x and 0.5 from the y of the rectangle when doing the addTileRect, but it still seems pretty hackish and forces more target branching code. It almost seems like some rounding issue somewhere.

Posted on May 03, 2012 at 6:44 AM