Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Avoid gaps in scrolling tiles

Author
Message
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Apr 2018 21:02
Is there a tried and tested technique for avoiding the occasional gap between scrolling tiles? It occurs every 4 or 5 seconds for just one frame, on a random tile border

In my scenario the tiles scroll from right to left. The size of the tiles is set as the sprites are loaded, according to a parameter file. There can be from 1 to 10 tiles horizontally on a layer. Tiles are scrolling at the rate of about 10-50 pixels per second
My setup is as follows:

Sprites are resized to an exact number of pixels
Sprites are set to snap (SetSpriteSnap() = 1)
Sprites are positioned side by side with no overlap and no gap
When Sprites are moved, they may be moved part of a pixel, but all sprites are moved equally and as mentioned, all are set to snap.
FPS = 60, and is constant +-5ms
VSync = 1
Window size is full screen 1920 x 1080. Virtual Resolution and actual screen resolution are also 1920 x 1080.
Tiles are not to the power of 2. They may be square or rectangular.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Apr 2018 21:29
I can't say I've ever noticed this. Then again, mine were likely all powers of 2. Is there filtering option you can change?
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 3rd Apr 2018 01:36
Yeah Coder is right, sprite snap is the likely issue. Also, using floats for the sprite position with snapoff helps I found.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 3rd Apr 2018 08:45
Thanks for the input.

I have tried with SpriteSnap on and off, there was no obvious difference.
I have solved my problem by overlapping the tiles by one pixel. I don't know if this is "normal", but it works for my purposes.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 3rd Apr 2018 08:57
My solution is to use to use an image atlas and have the edges of sprites extruded. I've used texture packer (not a sponsor) for years across different game engines.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 3rd Apr 2018 09:02
That didn't work? That's odd......been a while since I used as tiles but that was always the problem for me as I recall. It sounds daft, but what are they drawn in? I've noticed in the new Photoshop it defaults AA on for everything, and that makes the border semi transparent on everything. Its a collosal pain in the ass.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 3rd Apr 2018 10:00
I use Affinity Photo. Attached is one of my test tiles, it looks solid at the edges. I added a black border to help visualise the problem.


Quote: " the edges of sprites extruded"

What does this mean - set SpriteUVBorder?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Attachments

Login to view attachments
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 3rd Apr 2018 11:09 Edited at: 3rd Apr 2018 11:10
Its not something you do in AppGameKit it's a feature of most sprite packers, the reason this works is hard to explain but its a rounding issue, by extruding the edges by 1px you counter any fractional rounding issue as you allow the sprite to bleed into the 1px boarder rather than into nothing which will show a gap. this in simple terms shows the result http://www.matim-dev.com/texture-packer---get-rid-of-sprite-artefacts.html Unity and some other tools allow you to extrude a sprite on import, its common practice from what I see.
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 3rd Apr 2018 14:29
I struggled with this for a while, especially when I started sizing the game to non-native resolutions. For me the solution came when I extruded tiles by 1pixel in all directions so for example cut a 64x64 pixel tile from a 66x66px tile. You don't want snapping on - as mentioned by some others. Make all sprites move in float and any screen offset move in float. I've left UV untouched I think - the 1 pixel border works well.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 3rd Apr 2018 14:57
@c0d3r9 - you don't extrude the sprites yourself, you let the atlas tool do that and keep the source images as you intended. You'll need to use image atlas's though https://www.appgamekit.com/documentation/Reference/Image/LoadSubImage.htm
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 3rd Apr 2018 16:51 Edited at: 3rd Apr 2018 17:00
Quote: "Amazing. Every word of what you just said was wrong.
- Luke Skywalker"



I've encounter this problem many times using various forms of putting tiled sprites together in both DBP and AGK. It's actually an issue with how the image itself is loaded, as I discovered that when an image is loaded, especially images that are lower in pixel resolution, they aren't rendered 100% accurately, pixel to pixel perfection. If the image or tile has a higher pixel resolution you won't encounter this issue as often, but for images and tiles of lower resolution, you have to tell DBP or AppGameKit to load and render the image 100% without any type of filtering, which is the default for both.

To do this in DBP, when you load an image, add a , 1 to the end of the Load Image command.

To do this in AppGameKit, you must you the command SetImageMagFilter, and set it to 0.

This will save everyone allot of time, as there is no need to add an extra border to tiled images, which would make building tilemaps horribly complicated to use, and it saves you from having to overlap tiles, which than prevents you from having the tiles 'design' be able to flow together naturally, otherwise you're stuck with a very obviously blocky looking level.

Hope this helps everyone!
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 3rd Apr 2018 18:42 Edited at: 3rd Apr 2018 18:43
@c0d3r9 - yes that's correct, you import your 64x64 tile(s) into what ever atlas maker you have (such as texture packer), set the extrude size to 1px within the atlas maker, export the atlas image and info text file. The details in the text file will have taken into account the extrude so you'll still only load a 64x64 sprite, but you'll have those extra edge pixels so gaps wont be a thing.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Apr 2018 19:08
Quote: "To do this in AppGameKit, you must you the command SetImageMagFilter, and set it to 0."


Basically what I said from the start, just didn't know the command.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 3rd Apr 2018 19:54
@c0d3r9 - you don't do any extra pixel work, you load your tiles as they are into texture packer set the extrude value and it does the rest. when you export the results from texture packer you get a single (or multiple) large sprite sheets, the corresponding text file tells AppGameKit where in the large images your smaller ones are and their width and height. There is an AGK+Texturepacker tutorial video here that I found
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 4th Apr 2018 01:14
Honestly guys, all that work is a waist of time in my opinion, and is just going to make even more work for you down the line if you decided to change something. Just set the filter, this will give you pixel perfect looking images from your 2D program to AppGameKit, get rid of pixel bleeding, tiles will seamlessly fit together every time, and adding new tiles is as easy as drag/drop your new tile into your atlas grid, save, done, no fuss.
puzzler2018
User Banned
Posted: 4th Apr 2018 01:29
ouch
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 4th Apr 2018 02:18
Quote: "ouch"


I apologize if I sounded harsh there, it wasn't my intention. I was just making an opinion based on my 20 years of experience. I just don't see why you would have to add a white border to any image unless it's part of the design.

Sorry if I came off there rude.
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 4th Apr 2018 08:59
@c0d3r9 - Any good atlas maker tool should give extrude options. you could even roll your own tool in AppGameKit if you're feeling up to it.

@JLMoondog - I disagree , for better reliable results across different gfx drivers and platform I stand by extruding tiles\images in all situations regardless of filtering options.
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 4th Apr 2018 11:14 Edited at: 4th Apr 2018 11:21
Sorry I just disagree with you. I've created graphics for well over 10+ different platforms (mobile, console, 386, current pc, multiple DX v, OpenGL, ect.) with different setups and graphic rendering methods and chips/drivers and have never had to do this...sorry, just my experience. I always strive to create media to be usable and graphically consistent across as many platforms as possible. I just don't see the benefit and feel it just creates more work for the artist and coder. Especially down the line if you end up having to change/edit/or add to a tilemap.

If you can show me an example where creating a white border around a tile image benefits a program better than not using one, I would honestly like to see it and would gladly use this technique in the future if the situation ever presents itself. I'm always open to new ideas and learn to become a better artist/programmer.

Cheers!
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 4th Apr 2018 11:39 Edited at: 4th Apr 2018 12:10
okay I'll meet you round the back of the science block after school and we'll have a "chat" about it.

You don't create a white border, you copy the edge pixels, this gives the renderer some leeway when having to account for different filtering options, the render can steal a pixel if needed rather than showing a gap. There is a brief explain here (halfway down the page is the Extrude.

Now yes if you turn off ALL filtering and use integer values and don't move\scroll the tiles you "probably" wont have an issue with gaps but with filtering, mipmaps and sub pixel values you'll need the extrude.

Also there is no extra time involved, you just drop your tiles and images into (in my case) texture packer and press "publish", I don't need to spend any time extruding sprite manually or any of that.

I'll see if I put an example together this evening.
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 4th Apr 2018 20:09 Edited at: 4th Apr 2018 20:09
Well ofc I cannot replicate it (gaps between titles) now that I want to , either way I attached (source files + images) my test; loading a set of tiles with and without an extruded border and moving them together to see the difference.

Maybe if anyone has this issue they can see if they have the same in this test and see if extruding will eliminate it.

Attachments

Login to view attachments
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 5th Apr 2018 09:34 Edited at: 5th Apr 2018 09:34
For the scenario I was looking to show i'd expect to see faint lines between all tiles, if you use SetVSync(1) instead of SetSyncRate(60,0) does the line you describe go away?
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 5th Apr 2018 11:54
Yes that's the issue I've encountered over the years; on some machines there are gaps on others not, talk around town always puts this down the graphics drivers and how different ones round up\down sub pixels. You might want to try a larger extrude than 1px (I included the tiles to make a new texture packer file) ,I usually use a 4px extrude on my images with a 2px border.
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 5th Apr 2018 12:31
A '0' filter is great if your going for a pixel look and assets will never scale above or below their original, filtering is good if you're using high resolution assets that need to scale smoothly in game.

I don't draw any border around my images, I just import into Texture packer as they are and as they're designed to be seen and set the extrude and border values.
adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 6th Apr 2018 03:48 Edited at: 6th Apr 2018 04:04
The way that the sprite position is calculated in Supertino's gap code example can also introduce gaps in both sets of images because of floating point rounding.

When the sprites are first positioned, their X is set to x * tile_size.
After that, "dist" is a subtraction of two floats and then each sprite is moved by adding "dist" to its current X. This is where rounding errors is introduced: each addition is adding to the rounded result of the previous addition which can cause a column to be off by a bit occasionally. When the window size and virtual size are multiples of the tile size this might be less obvious.

To be smooth, there needs to be a base value from which all other sprite locations are calculated. GetTweenCustomFloat1(move_x_tween) is already the X for the left tiles, so just use it as the base.

I've modified Supertino's example. I've changed the virtual width to 475 and made the bottom row sprites base their position on the tween's actual value. I get a gap in the top two rows of the top and bottom tile sets at around 50.145. The bottom row is fine because the rounding errors are not being compounded.



This particular code is gapless for me no matter which filter is used.
adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 6th Apr 2018 07:38
There also appears to be some rounding error with either SetSpriteX/SetSpritePosition or GetSpriteX.

These values are off quite often:

I would think that the value returned by GetSpriteX would be the same set with SetSpriteX...
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 6th Apr 2018 10:43
@adambier - interesting stuff, I had assumed as I was moving all tiles (sprites) on the same frame by the same value it would not be an issue but yes as they start at different positions issues down the line can creep in.
adambiser
AGK Developer
8
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 6th Apr 2018 13:52
@Supertino - I had to tweak the numbers you had and make the tiles move much more slowly in order to see the gaps myself. I think with your original virtual width and window width, the gaps shouldn't appear.
Your original virtual size and window size are at a 2.5 scale so a tile width of 40 is a drawn as 100 pixels. I would think that with your values there shouldn't be any gaps, but c0d3r9 said that they saw them. Maybe weird float mismatch with Get/SetSpriteX is causing the gaps sometimes? I really don't know.

Login to post a reply

Server time is: 2024-05-11 03:51:33
Your offset time is: 2024-05-11 03:51:33