Java - Game Animation Techniques - java

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.

Related

Circumvent frequent repaint()-calls for tile-based game

I just started to work on a tile-based simulation game (3D but the graphics will all be 2D pngs/bitmaps). The graphical concept is similar to e.g. gnomoria. I managed to implement the graphical part of the world using a custom subclass from Panel (AWT) that draws the cubes starting at the lowest level left back and works its way up. This way the images of the cubes fit together correctly, but the painting takes too long for a 196*196*100 cubes big world.
Now what I'm asking for are methods to circumvent the repainting of the whole world everytime it changes a little bit.
I think I got a decent idea for the changing process of a single top layer block by just repainting the visible side (either top/left/right) so that it isnt necessary to repaint all the following cubes. But what I'm unable to solve is the repaint whenever I'm moving the screen, i.e. moving the world using a KeyListener. My first idea was to just move the Panel in the Frame but that didn't solve the problem as it still redraws everything if I move the world. Btw I already use hardware acceleration which accelerated :D things a bit, but it is still far away from the goal.
The current result is that the Panel moves, but as soon as something enters the screen that was offscreen before, it repaints this section. The repaint is quite fast but not fast enough to not be visible and disturbing.

Make Custom Shape JavaFX

I am making a 2D game in JavaFX and when detecting collisions, I am getting rather inaccurate results due to the player sprite being set as the fill of a rectangle and therefore not having the intended borders. Is there a way I could make my own shape so thatI could get as accurate as possible?
Another idea I had is checking if the pixel that collided was transparent and then not ending the game if it was. Does anyone know of a way I can get the coordinates of the pixel that collides so that from there I can use PixelReader to check?
If anyone knows a better way, please let me know!
Thanks,
Ethan
There are different ways to do this. Here is one way I have used with good success. I would make hit boxes, that were themselves rectangles. Then during collision detection, I would iterate through all the hit boxes to see if they collided with the flying projectile's hit boxes.
What this allows you to do is fill in complex shapes with smaller rectangles. For example a plane would have one long horizontal rectangle and one smaller rectangle crossing at the middle.
Currently I am using libGDX. In libGDX I use their Polygon object as stated here. https://stackoverflow.com/a/28540488/1490322 I have not seen similar functionality in JavaFX, but it would not be hard to copy what libGDX is doing into JavaFX code... their code is open sourced.

How do I improve LibGDX 3D rendering performance?

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.

Android OpenGL ES 1.1 Combine Multiple Textures

I'm developing an Android game using Java, and I am currently on trying to figure out an efficient way of rendering the necessary textures. Suppose you have a Grid, similar to a Checkers board layout, and Tiles to fill that grid, as in each square on the board. That is the concept of what will be displayed. Currently, I am drawing each tile one by one. All of the texture loading is done upon creation and is only done once, not upon drawing. Now, for what I want to do. I've noticed that drawing all one by one, although fast for what I'm doing, it can be glitchy. In my game, the user has the ability to drag the "board" to view different areas. As of right now, I'm only allowing the necessary tiles to be drawn depending on the location of the top left visible tile. As I said, it works quite fast, but, once the user starts interacting more or dragging faster, the rendering starts to have difficulties and isn't as fast as it should be. This causes little separation in between the tiles. It's not large, just large enough to be noticeable. What I want to do is to basically place each texture in a certain location as defined by the grid, thus creating a new texture containing the viewable area, and then render that entire area as opposed to render each tile separately. I've done a lot of research and already looked at many questions, but I still have not found something that will help my cause. I've read that rendering to texture using a framebuffer may help, but I haven't found any easy-to-follow tutorials or examples, just a lot "here's the code, no explanation" or "here's something similar to what you want, but it's using different things." So, if someone could point me towards a good tutorial/example, or post a valuable answer, I would be very grateful. I'm avoiding OpenGL ES 2.0 because I want my game to be compatible with many devices, and for what I'm doing, 2.0 is not necessary.
For a quick summary of what my code does for further explanation:
for(go through visible rows){
for(go through visible columns){
drawTile(); //Does the texture binding and drawing for each tile
}
}
What I want:
for(go through visible rows){
for(go through visible columns){
loadTileTextureIntoGridTexture();
//I want it to combine the textures into one texture
}
}
drawGridTexture();
Doing it the second way will only have one whole texture to render as opposed to visibleRows*visibleColumns textures to render.

Why do I have lines going across my libgdx game using Tiled?

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

Categories