Pages

Showing posts with label libgdx. Show all posts
Showing posts with label libgdx. Show all posts

Sunday, August 31, 2014

First prototype!

Hi guys!! :))

I finished my first game prototype! You control a dog that runs and jumps over pits! Tap right side of the screen for a big jump, and left side of the screen for a smaller jump.


I haven't thought of a name yet.

Its a prototype. I plan to remake all graphics, probably will hire an artist. Will add animations for falling, jumping and standing (at the start screen), also sounds and a nice background is planned.

Please share your thoughts!
DOWNLOAD:

Wednesday, August 27, 2014

Libgdx supporting different screensizes

I finally fixed the density problem! I should have read the docs and libgdx wiki more careful, that would have saved me 3 days! The fix was pretty easy. There was no need in making several copies of each image in different resolutions, not even setting any coordinate to relative instead of absolute. Libgdx is a game engine, a framework, where most common problems have easy intuitive solutions.

I ended up adding just a few lines of code instead ~50+ of my noob-solution code. In the create method:

        viewport = new StretchViewport(480, 800, camera);

The StretchViewport stretches viewport to screen. You can use other ones (check libgdx wiki), so that you don't stretch, but show black borders on the sides of screen. But my game is locked in portrait mode, so there will probably be almost no difference in aspect ratios on different devices. 

and the resize method:

        @Override
public void resize(int width, int height) {
viewport.update(width, height);
}

The game now looks exactly the same on 480x800 and 1080x1920 screens. Just need to add Linear filter to images so they dont look too pixelated. In my case i added the filter to my assets.pack after TexturePacker.

Thursday, August 21, 2014

First game prototype almost done! One problem to solve... different densities

 

So there it is. You can see a device with 480x800 resolution on the left and a device with 1080x1920 on the right. This is wrong for sure. Problem is that when making an native android application there are folders for different screen densities and the app chooses assets depending on screen densities/sizes. There is another way in libgdx to deal with it, but im not familiar with it yet. Probably you need to load several sizes of one image and switch between them depending on screen size. That is really easy to implement using the Gdx.graphics.getHeight() and choosing different images to load depending on the value returned from that method, but i better learn about the ready solution first. There are some probable pitfalls concerning image coordinates if they are of a different size. Probably this can be solved by not using actual pixel coordinates, but using instead proportions of the screen, like Gdx.graphics.getHeight()/10 etc.

Tuesday, August 19, 2014

libgdx: making camera follow player

So, i had this problem. Looked everywhere and couldn't find a decent tutorial, actually any info, so here it is:

In class:
OrthographicCamera camera;
in constructor:
camera = new OrthographicCamera(Width, Height);
camera.setToOrtho(false);
in render method:
camera.position.set(player.x, player.y);
camera.update();
batch.setProjectionMatrix(camera.combined);
The last line is what was missing from all those tutorials, and the single line that makes the difference.