I'm using LibGdx and Tiled and when moving around the screen, there are both horizontal and vertical lines appearing on the game. I can post any code you need, if necessary. How do I get these lines to stop?
Here's a gfycat gif of the lines:
http://gfycat.com/FastUnnaturalAmericanwirehair
Edit:
Here's a small bitbucket repository, as small as I could get it that has the same glitch in it:
https://bitbucket.org/Chemical_Studios/example-of-line-glitch/src/8eeb153ec02236d836763072611bd7aa55d38495/minimalExample/src/com/weebly/chemicalstudios/minEx/?at=master
This is because you need to add a padding to your tiles.
This is a pretty common problem and you are not the first to encounter it. Basically due to rounding errors when scaling and panning around, sometimes you will render the area "between" two tiles, which will result in nothing being rendered -> black background colour comes through.
You basically need to use some tools to add the padding to your tileset. In this forum thread I explained how to do it.
There is also one more questions regarding this topic on stackoverflow here.
When you have rounding errors you can always force the number to snap to the grid you want. In my case that looked like this:
gameCam.position.x = (float) Math.round(player.b2body.getPosition().x * 100f) / 100f;
Because I used a pixels-per-meter constant of 100f throughout the game, to scale everything
Related
I read all the million posts about the problem with black lines shown on screen when rendering tilemaps on libgdx. All the solutions talk about add padding to the tile sets. So I did it, but it didn't solved the problem.
I think maybe I didn't understand it well, so I will post here the process I'm doing, and I will be glad if someone can point out my mistake, if any:
This is an image of my initial tile set:
This is an image of my tile set after adding padding using GIMP plugin which was suggested from this post:
Then in Tiled, I add this tileset and set Margin to 1px and Spacing to 2px like written in this post.
Now as I understand the problem should be solved, but still when I run the program I get:
I can add code parts if you want, but there is really nothing special the way I render my map- just load it with TmxMapLoader and render with MapRenderer (using camera also, of course, otherwise the problem wouldn't appear).
I know this thread is very old, but it took me two hours to figure out the solution myself. So in case somebody has the same problem in the future:
I noticed that only some tiles behaved like this - for example, a grass tile would, a water tile wouldn't. Even if they were used on the exact same position in the map.
For me the problem was - apparently - that my PNG tile sheet's height was not a power of 2. A few days before, I added a line to an existing tilesheet and changed the height from 1024px to 1056px. After a lot of experimenting, I found out that after removing this line again, the black stripes would disappear.
Load your maps like this:
TmxMapLoader.Parameters() params = new TmxMapLoader.Parameters();
params.generateMipMaps = true;
TmxMapLoader mapLoader = new TmxMapLoader();
TiledMap map = mapLoader.load("pathToMap", params);
I had the same problem I fixed it by changing the size of my spritesheet to a power of two
example :
640*640 --> wrong
512*512 --> right
So, after ages of searching all I ever keep coming across is spritesheet. I am planning on making a multiplayer game where the changing of items and gear happens regularly. I want to have fun creating new items, but with spritesheets it can get ridiculous redrawing the same movement and having choppy transitions.
cdn.akamai.steamstatic.com/steam/apps/524970/header.jpg?t=1475608912
Here is the game that kind of inspired me. Very smooth characters and when I watch the animation it is basically just rotating parts, or expanding the image. Am I missing something, or is there an animation technique where you can easily just rotate limbs, or perhaps just expand the image without having to constantly sift through images. Some pseudo code could be ImageWidth = ImageWidth * 1.5 to create a bigger version. Or ImageRotation = 20 where the image rotates at a certain point. Just wanting to know what people use to animate themselves or if you have advice for me.
I'm working on rendering a tiled sphere with LibGDX, aimed at producing a game for desktop. Here are some images of what I've got so far: http://imgur.com/GoYvEYZ,xf52D6I#0. I'm rendering 10,000 or so ModelInstances, all of which are generated from code using their own ModelBuilders. They each contain 3 or 4 trianglular parts, and every ModelInstance corresponds to its own Model. Here's the exact rendering code I'm using to do so:
modelBatch.begin(cam);
// Render all visible tiles
visibleCount = 0;
for (Tile t : tiles) {
if (isVisible(cam, t)) {
// t.rendered is a ModelInstance produced earlier by code.
// the Model corresponding to the instance is unique to this tile.
modelBatch.render(t.rendered, environment);
visibleCount++;
}
}
modelBatch.end();
The ModelInstances are not produced from code each frame, just drawn. I only update them when I need to. The "isVisible" check is just some very simple frustum culling, which I followed from this tutorial https://xoppa.github.io/blog/3d-frustum-culling-with-libgdx/. As you can tell from my diagnostic information, my FPS is terrible. I'm aiming for at least 60 FPS rendering what I hope is a fairly-simple scene of tons of polygons. I just know I'm doing this in a very inefficient way.
I've done some research on how people might typically solve this issue, but am stuck trying to apply the solutions to my project. For example, dividing the scene into chunks is recommended, but I don't know how I could make use of that when the player is able to rotate the sphere and view all sides. I read about occlusion culling, so that I might only render ModelInstances on the side of the sphere facing the camera, but am at a loss as to how to implement that in LibGDX.
Additionally, how bad is it that every ModelInstance uses its own Model? Would speed be improved if only one shared Model object was used? If anyone could point me to more resources or give me any good recommendations on how I can improve the performance here, I'd be thankful.
If the tiles are eventually intended to be solid, one improvement you can make is to turn on back-face culling. This will cause any faces not facing the camera to not be rendered (i.e. one side of each face becomes invisible). For a sphere that means the GPU would only need to render about half the faces.
Combining the object into a single Model may also have a large impact. It may be the difference between 10,000 draw calls and 1 (it depends on how smart that modelBatch object is, as it might do the combining behind the scenes). If the user will sometimes be zoomed pretty close a chunking approach might help so that you can continue doing frustum culling.
I'm using LibGDX to make a platformer. I'm using square tiles for the platforms but when they are drawn some of them have gaps between them. When I zoom in/out or move the camera around the gaps move position.
More details:
Tiles are 32x32 and I have tried both 32x32 and 64x64.
Tiles are lined up 32 pixels apart (e.g. first tile would be x=0 y=0, second x=32 y=0, and so on in both x and y directions).
The gaps are not texture artifacts as I have checked this.
I use the TexturePacker with padding.
My best guess is that it is a problem when converting the textures to screen coords but have no idea how to fix this and I couldn't find any solution. I have checked and double-checked my precision with tile sizes and lining them up.
Has anyone had the same problem or know how it fix it?
I got it fixed by setting the duplicatePadding field of the TexturePacker.Settings class to true.
Example code:
import com.badlogic.gdx.tools.texturepacker.TexturePacker;
import com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings;
Settings settings = new Settings();
settings.maxWidth = 1024;
settings.maxHeight = 1024;
settings.duplicatePadding = true;
TexturePacker.process(settings, "source", "destination", "name");
Well, I'm here to save your day!
The solution is called "Edge padding". Now if you are working with tilesets, I can assure you that this will work.
Personally I'm using Tiled which allows me to adjust margin and spacing in my tilesets. The only downside by this is that you'll have to use GIMP with this plugin: http://registry.gimp.org/node/26044
This plugin will let you apply edge padding to your tileset and voila! No more ugly artifacts.
Bleeding
Gaps
The short answer is that it may be your filter, which likely needs to be set to NEAREST.
Might also want to check out the working tutorials at Libgdx.
It's called "texture bleeding". You need to add padding to your tiles so that when the texture bleeds, it can collect the correct pixel data to fill the gap.
I know it's a bit late to answer on this post, but when I was looking for a solution I came here.
However, for me I found a much easier way to get rid of the flickering or gaps that appear randomly between the tiles.
I simply added a cast to the very long decimals I got for the player's position:
camera.position.set((int)robot.position.x, (int)robot.position.y, 0);
That made the player move very weirdly and to make him move smoothly again I added a cast to its render method aswell:
batcher.draw(robotSprite, (int)robot.position.x, (int)robot.position.y, 16, 16);
Et voilĂ ! Working perfectly for me.
I would post my solution here and what I had tried for Libgdx about this problem.
--
T1. Make original spritesheet (no atlas file) that downloaded from somewhere to padding 2.
A1. This would be impossible for repacking the spritesheet that have no atlas, even if you find a slice/splitter tool, it should be a bunch of images that need to be repack properly for TiledMap(.tmx)
A1(Updated). Script that provided by #Nine Magics would be the best way to do this! (I use this as my final solution)
--
T2. Use TiledMapPacker that provided by libgdx-nighty or gdx-toolg, The batch code should be:
java -classpath "gdx.jar";"gdx-natives.jar";"gdx-backend-lwjgl.jar";"gdx-backend-lwjgl-natives.jar";"gdx-tiled-preprocessor.jar";"extensions/gdx-tools/gdx-tools.jar" com.badlogic.gdx.tiledmappacker.TiledMapPacker "PathToYourProject\android\assets\RawMap" "PathToYourProject\android\assets\Map" --strip-unused
A2. The output .tmx that could not be readable by Tiled If you are using complex folder path to category your .png files. And the output file could be possibly failed to load by AtlasTmxMapLoader.
--
T3. Camera position correction, make camera position to integer. The code liked #Julian or #strangecat from libgdx tiledmap flicker with Nearest filtering
A3. I use this solution for no problem, and also post my code that different from them.
float cameraX = (int)(mainCamera.position.x * Game.PPM_X) / Game.PPM_X;
float cameraY = (int)(mainCamera.position.y * Game.PPM_X) / Game.PPM_X;
float cameraZ = mainCamera.position.z;
mainCamera.position.set(cameraX, cameraY, cameraZ);
And also load it with TmxMapLoader.Parameters
TmxMapLoader.Parameters params = new TmxMapLoader.Parameters();
params.textureMinFilter = Texture.TextureFilter.Linear;
params.textureMagFilter = Texture.TextureFilter.Nearest;
params.generateMipMaps = true;
assetManager.load(TILED_MAP_SETS.FIRST_MAP, TiledMap.class, params);
If you used PPM and want to move pixel by pixel, you could use this integer correction for your game, If not you could just convert the position to integer.
I almost wasted whole day to slove this, hope these investigation could help every game developers :)
Edit(2018/04/21)
I found out that Unity is also having the same problem, but I haven't tested If Libgdx have 2x Anti-Alias setting by default. Libgdx might fix the issue as Unity by turning off the Anti-Alias.
I've got this BufferedImage object that's guaranteed to contain only one color. I'm using it to display a sample image to show size, shape & hardness of a brush in a painting tool. I've tried several different blur implementations for hardness... the latest, that seems to work fairly well is this Stack Filter written by Romain Guy.
I've got 2 problems.
Faster on 1 channel than 4?: None of the blur filters I've tried seem to be quite fast enough... I realize this question has been asked before (and I'm not quite ready to try pulling in FFTW from C), but I'm wondering if there's a way to perform the blur using ONLY the alpha channel bits? The image only contains one color, so none of the other bits will change across points anyway and my thought is that this would cut the number of calculations for the blur to about 25% of the whole blur operation and I figure that's likely to result in a noticeable improvement in performance? I've not been able to find any information about this being tried via web search.
Eliminating the Dark Halo: Every time I try a different blur algorithm I end up having to rewrite it to get rid of the dark shadow around the shape caused by blurring in "black" from colorless pixels where nothing has been painted in yet. I've read about this and I'm using (as far as I know) INT_ARGB_PRE image types, which I remember reading as a solution to this problem. Am I missing something in that solution? Do I need to preformat the image in some way to make it interpret all the empty pixels as white instead of black?
Thanks!
You may find this interesting:
http://www.jhlabs.com/ip/blurring.html
The dark halo issue is discussed, all source code is available as as far as I can recall, it only uses standard Java SE stuff.