rendering with subpixel accuracy artifacts

When I postion a sprite with subpixel accuracy I see artifacts around the bottom and right edges of the sprite. It’s as if its trying to average partial pixel values at the edge of the sprite with image data outside the edge of the sprite but is treating the image data that is outside the edge of the sprite as having non-zero alpha.

Is there a way to get cocos2d-x to not have these artifacts but to actually use subpixel accuracy?

I know I can just round to whole pixels but I’d like to actually use subpixel accuracy because I think it might make for smoother animation.

Will padding my sprites in the sprite sheet fix the problem? — I want to find out if this will actually fix it before trying this because I generate my own sprite sheets and it will be a little bit of work to implement padding. Does anyone know?

Most likely padding the sprites will fix that. We are using spritesheets and always add the sprites with 1px or 2px of padding.
If you post a screenshot with the artifact we could make more out of it.

Cristian Cristea wrote:

Most likely padding the sprites will fix that. We are using spritesheets and always add the sprites with 1px or 2px of padding.
If you post a screenshot with the artifact we could make more out of it.

So do you pad your sprites using the “offset” and “sourceColorRect” fields in the plist? Because I’m thinking I’m going to need to modify my sprite sheet generation script so that it supports generating sprite sheets +.plists that use these two fields. (Currently, I use offset = {0,0} and sourceColorRect == sourceSize as a rectangle)

I’m using TexturePackerPRO to do the spritesheet packing and they have a border padding option. From looking at the generated plist offset is {0,0} and sourceColorRect == sourceSize as you mentioned. The difference is in the frame like this:

no border padding

frame
{{0,0},{74,74}}

with 2px border padding:

frame
{{2,2},{74,74}}

Basically is offsetting the position of each frame with 2px

Cristian Cristea wrote:

Basically is offsetting the position of each frame with 2px

I see … thanks that’s actually an easier feature to add to my script.

Just as a follow-up, doing padding as Cristian Cristea described fixed the problem I described.