flixel icon indicating copy to clipboard operation
flixel copied to clipboard

Serious floating-point artifacts on CPP FlxTilemap & FlxSprite

Open cwkx opened this issue 11 years ago • 63 comments
trafficstars

pic

I made all transparent tiles in my tileMap bright green to highlight the issue. The boundaries of some tiles are showing pixel data from their adjacent neighbours.

(1) This only occurs on some resolutions. Try lots of different resolutions. (2) This occurs infrequently; best way to "find" it is by moving slowly in x and y axis. Most likely some floating point issue.

Using latest version from github.

cwkx avatar Mar 02 '14 22:03 cwkx

Noticed that too. I guess normally you would use tileScaleHack of your FlxTilemap but that doesn't improve it. I have found a workaround by using the PixelPerfect Scalemode.

primaerfunktion avatar Mar 03 '14 16:03 primaerfunktion

Seems to be fairly easy to repdroduce (Project Jumper demo for example).

@Beeblerox Any idea what could be causing this?

Gama11 avatar Mar 03 '14 18:03 Gama11

This might not be a bug with HaxeFlixel, check out this GameMaker article on this issue and how to prevent it: http://www.yoyogames.com/tech_blog/8

gamedevsam avatar Mar 25 '14 17:03 gamedevsam

@gamedevsam I think this is a different issue than the one that's described in the article. We also have issues with tilemap scaling on native targets, but that's a different problem and fixed by the tileScaleHack.

Gama11 avatar Mar 25 '14 17:03 Gama11

I'm having a similar issue with the Linux version of my game. Strangely, this only occurs in Linux (Ubuntu 14 64-bit, running from a flash drive via UNetbootin).

screenshot from 2014-05-19 21_38_26

I also noted the same issue in Flappybalt, I'll grab a photo when I can. This is not limited to tilemaps, however. Don't Move uses an image atlas, which could explain the problem, but Flappybalt doesn't.

edit: Note that setting pixelPerfectRender to false and using software rendering (by setting --window-hardware=false as suggested by @jgranick) both had no effect.

steverichey avatar May 20 '14 12:05 steverichey

It happens in my game as well. I'll post a screenshot soon. I'm using Windows 7 64-bit, and compiling the game to Windows. I have two versions, a server and a client. Both versions have different camera settings, and the issue only happens on the client version. I'll post the two camera settings soon, maybe it will clarify the issue.

Ohmnivore avatar May 20 '14 14:05 Ohmnivore

screen

Actually I just realized that it happens in both the client and server versions, but it's less apparent in the server version. In the client version it happens from time to time when the camera is moving, but the issue only appears for a split second, then it's back to normal. I was lucky enough to hit print screen as it happened.

screen2

You can see here that the black lines are actually edges of the tile's adjacent tile in the tilemap:

screen3

gamedevsam's link is definitely relevant. I think it identifies pretty well the problem, and it can be resolved with spaced tilemaps. Can HaxeFlixel load spaced tilemaps?

Ohmnivore avatar May 20 '14 15:05 Ohmnivore

Can HaxeFlixel load spaced tilemaps?

Yes. https://github.com/HaxeFlixel/flixel/issues/434#issuecomment-34834484

Gama11 avatar May 20 '14 15:05 Gama11

Okay, adding a spacing of 2px and the smearing they talk about in the link solved the issue.

Ohmnivore avatar May 20 '14 17:05 Ohmnivore

My issue doesn't seem to be limited to tilemaps, should I open a separate issue? If anyone else has access to a Linux environment, let me know, and I can send you the Linux build above (or you can just load up Flappybalt v1.1).

steverichey avatar May 20 '14 17:05 steverichey

@steverichey This issue isn't limited to tilemaps for @cwkx either.

Gama11 avatar May 20 '14 17:05 Gama11

I have the artifacts too and I don't use any tile spacing. I could bet that this is a Float to Int convert issue. hxenyo_tilefuck

I guess the GM solution might work but is there any chance to automate this process even for tilemap textures without spacing? Since I am trying to port a lot of tile maps I've done without. And that would be quite an overkill to handle manually.

c023-DeV avatar May 22 '14 11:05 c023-DeV

I believe that my issue is unrelated to this. I suspect that the graphic issues shown above have to do with improper drivers.

steverichey avatar May 22 '14 18:05 steverichey

For those wondering how to reposition tilemaps: http://registry.gimp.org/node/24816

Ohmnivore avatar May 22 '14 22:05 Ohmnivore

Thank's ... Tried that script with Gimp 2.8 it didn't work for me (image sizes stayed the same), but I get the point - one 'could' script the whole level design in PS/Gimp then print that to paper - cu t and re-size it and scan it back in.... sorry... just no solution for me. And since my editor doesn't support nor need spacing for things to work, I'd have to use 2 sets (one for the editor and one for HF - dats stupid and rather a no-no) - can't this maybe be resolved by adding some 'nearest neighbor scaling maybe or optionally using Ints instead of Floats for the scroll/scale or whatever actually causes the issue ... cus I don't understand it -if I have a 16x16 tile then this thing should BE 16x16px and not 16.01x16.01 =/

or is it 'the NeW Way' to handle tilemaps now? With clamping and spacing? I'd have loads of awkward image sizes and recalculating to do on that. Sorry, I'm a dick.

c023-DeV avatar May 23 '14 09:05 c023-DeV

Whoa calm down, this is an open-source project where people contribute their time and efforts for free. If there's a bug it should be reported and then fixed by whoever feels like fixing it. I'll try to add a loadNativeMap function which will act exactly like the loadMap function, but the asset passed to it will be transformed into an appropriate tilemap at runtime: i.e.: 1px border, 2px spacing, and right-most and bottom-most pixels extended. I'll try and have this done by Sunday. That way you can use your assets the way you always do, I admit that I don't want to need two versions of a tileset either.

Ohmnivore avatar May 23 '14 22:05 Ohmnivore

@Ohmnivore Maybe it's be better to add a FlxBitmapUtil.addSpacing() to pre-process the asset before passing it into loadMap()? That approach seems more flexible (could also be applied to sprites for example).

Gama11 avatar May 23 '14 22:05 Gama11

Good idea, I forgot about sprites.

Ohmnivore avatar May 23 '14 23:05 Ohmnivore

Hey guys, just made a first version: https://gist.github.com/Ohmnivore/41eaca877d202b875b65 To my understanding FlxSprite also accepts a TextureRegion for loadGraphic, so this can be used to fix the issue for sprites and tilesets. For now my code assumes that frames/tiles are square, I'm gonna add variable width and height support in like 15 minutes.

ex: map.loadMap(mapdata.arr, TestFeatures.artefactFix("assets/images/gridtiles2.png", 16), 16, 16, 0, 0, 1, 1);

Ohmnivore avatar May 24 '14 01:05 Ohmnivore

Okay, updated that gist to the new version. Now you can pass tile width and tile height. ex: map.loadMap(mapdata.arr, TestFeatures.artefactFix("assets/images/gridtiles2.png", 16, 16), 16, 16, 0, 0, 1, 1);

Ohmnivore avatar May 24 '14 02:05 Ohmnivore

@Ohmnivore Sorry for being demanding. I just talk that way. The gaming biz made me that way, of course I know that this isn't a commercial product where a 'customer' would demand progress. I saw a serious issue and didn't want to lay that off to a toolchain and sprinkled in some sarcasm. I guess it is in every ones interest to make this work. And at the time being, this is all I can do - point out things and share my experience. I'm just an artist working with this.

I'll look at that update later or when you are happy with it. Sounds usable.

c023-DeV avatar May 24 '14 20:05 c023-DeV

I'm satisfied with the gist, I don't think I'm going to add anything. I haven't spotted any issues with it yet, and seems to work fine. BTW I have a terrible sarcasm detector. No hard feelings.

Ohmnivore avatar May 24 '14 21:05 Ohmnivore

Hi, I think I have a similar case of this problem but using sprite's makeGraphics.

I'm using sprites to debug my BSP Tree algorithm and noticed that in some cases one or more sprites are printed with a tilt of one pixel. As you can see in this ss (i drawed a white box behind to spot the tilts more easily):

haxe_bug

Who can I apply @Ohmnivore 's soluction in my case? Or there is any flixel/haxe/openfl release with a correction for this problem coming in a near future?

luizdepra avatar Jun 26 '14 14:06 luizdepra

@RawArkanis Any chance you could share a simple test case for that? It may or may not be the same issue, but I'm curious all the same.

JoeCreates avatar Jun 26 '14 14:06 JoeCreates

@JoeCreates, sure! Here are a project with the relevant code: https://hostr.co/qNqCntSHi3RL

First I thought it was a code mistake, but this code work perfectly on flash target and give problems on neko and windows.

luizdepra avatar Jun 26 '14 15:06 luizdepra

RawArkanis this looks awfully similar to the problem I had. This can fix it: https://gist.github.com/Ohmnivore/41eaca877d202b875b65

Ohmnivore avatar Jun 26 '14 15:06 Ohmnivore

This might also be related?

Gama11 avatar Jun 26 '14 15:06 Gama11

Apparently this issue affects Kindle Fire HDX 7 (3rd Gen), and Kindle Fire HD 7 (2nd Gen). Recent fixes resolved it for iOS, Mac, and Linux, so this was news to me. Image via Amazon:

0032981701_1403765534_don_tmove_vertical_lines_kfhd7_screenshot

steverichey avatar Jun 26 '14 17:06 steverichey

Hey guys, I'm now developing for Android and testing on my tablet. I still get this issue, it's not a game breaker but it sure is annoying. My old method of dealing with it: https://gist.github.com/Ohmnivore/41eaca877d202b875b65 somehow doesn't work anymore. I'm wondering why, but I'm also wondering how you guys got around the issue?

Ohmnivore avatar Oct 26 '14 04:10 Ohmnivore

@Ohmnivore does it not working or it not compiling?

Beeblerox avatar Oct 26 '14 06:10 Beeblerox