Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (798)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (865)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Libgdx: Problems with scaling  (Read 1084 times)
0 Members and 1 Guest are viewing this topic.
Offline Apo
« Posted 2019-02-18 16:33:26 »


I made a game with the resolution 960px x 960px. Everythings works fine, but when I try the web or the android version, there are some unsightly strokes as you can see here
I use one image sheet for all images. My pixel size for a tile is 24x24 and after 24 pixel the next sprite is in the image.
The problem: You can see, sometimes one pixel of the next or previous sprite is shown. In my opinion it is a problem with the scaling because the html version and the android version has to be scaled to fit to the screen.

Now my question ... what can I do? One sprite = one image? But then I have MANY images ...
Offline KaiHH

JGO Kernel

Medals: 732

« Reply #1 - Posted 2019-02-18 17:54:32 »

The problem is likely nearest neighbor filtering sometimes taking false/wrong neighbor texels from another tile when sampling, because the corners/edges of your tiles use texture coordinates at the very corners/edges of the respective texture tile texels within the texture atlas. The solution is to offset and scale your texture coordinates, such that at the corners/edges of your tile, you do not use e.g. (0,0) or (1,1) as texture coordinates - which would be situated at the corners/edges of the texture - but use texture coordinates that lie exactly at the center of a texel.
The following image should visualize this:

The black raster should denote your texels. So at the center we have four texels. The red square should denote your tile and the texture coordinates it was given for its corners. (for this example, just suppose that the texture coordinates are from (0,0) to (1,1) for a single tile).
So, the whole thing is a tile mapped to a 2x2 texels texture part within the texture atlas.
The green part is the texture part of the tile we're interested in.
The blue arrows then tell, that for the pixel at this very location (on the red edge), the nearest neighbor could be to the left of that edge sometimes, or to the right of that edge.
The smaller green square is the correctly down-scaled texture coordinates. This should still apply to the outer red/black square, but uses texture coordinates that map to the respective centers of the texels, so that no nearest neighbor filtering will ever choose a false neighbor outside of the tile's texture space within the texture atlas.
Offline Apo
« Reply #2 - Posted 2019-02-18 19:30:20 »

Thanks for your reply.

Now every image in the imagesheet is 26px x 26px and repeats the last pixels and everythings looks good.
Like I said big thank you.

Now the game looks better in html and at android devices.
Pages: [1]
  ignore  |  Print  

Riven (77 views)
2019-09-04 15:33:17

hadezbladez (4299 views)
2018-11-16 13:46:03

hadezbladez (1539 views)
2018-11-16 13:41:33

hadezbladez (4438 views)
2018-11-16 13:35:35

hadezbladez (860 views)
2018-11-16 13:32:03

EgonOlsen (4149 views)
2018-06-10 19:43:48

EgonOlsen (4851 views)
2018-06-10 19:43:44

EgonOlsen (2800 views)
2018-06-10 19:43:20

DesertCoockie (3705 views)
2018-05-13 18:23:11

nelsongames (3996 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!