I want to make a game with Java and LWJGL. In many videogames you can see the black fields at the top and the bottom of the display, which is used to size the display in the resolution the game can work with.
I searched for this two days, but maybe I used wrong keywords.
So is there any possibility I can make this with LWJGL. Maybe a method I can use?
Related
I have been trying to support multiple screen resolutions for Android, i have tried all the viewports but non of them fit my game well, my game is like Asteroids where the ship wraps around the world when it reaches the edge of the screen. if i use Fitviewport on some resolutions the ship wraps around before it reaches the edge of the screen and if use Fillviewport the ship goes out of the screen instead of wraping around, if i use Stretchviewport the game looks horrible the other viewports are not working well either, So i think the only solution for me would be to create diffrent assets for diffrent resolutions, now how do i go about doing that?
try using ExtendViewPort and provide the minimum and maximum viewports your app should support. The maximum size will limit how much the world is extended and the minimum how much shrink
I've never used LibGDX, but it sounds like your problem is with different aspect ratios, not different resolutions.
So if I were you, I'd try Fillviewport, and then I'd calculate everything manually to make sure to reset the location of the ship (and any other objects) to the other side when it collides with the edge of the screen.
This is not super easy, so this is why a game like PewPew will use a square frame for its asteroids-mode instead.
I just finished my first coding class (IB Computer Science, if that helps), and I decided I wanted to make my first game.
The game world I have currently is a top-down view of the terrain. Each part of the terrain is made up of squares (it is very similar to the way Dwarf Fortress looks). I have been able to get it to output to console, using characters for stand-in graphics, but my course covered very little on graphics work.
What is the best way to create a grid of sprites or colored squares inside a JPanel? I have been able to display BufferedImages before, but have not been able to align multiple BufferedImages to get a grid.
As of now, I have an '2D' ArrayList, just an ArrayList of an ArrayList, making up my game world. It all works great when I use a double for loop and System.out.print("");
Check the oracle documentaion for Layout Managers. The one you are looking for is Grid Layout.
If you feel fancy, you can upgrade to JavaFX, and use a Grid Pane instead.
I have been trying to "cut" an image for some time now, I ll explain why and what I tried.
So I wanted to create an hp "bar" except it's not a bar but a heart and so I though it would be easy all I had to do is have two pictures draw them on top of each other and then just cut one to make it appear as in hp was being lost, but I was not able to find a way to cut the image.
Setting the height just resizes the image as you might have guessed
I tried using textureRegion to kind of hack it but it didn't go so well
I found a method called clip begin which also uses scissors but for some reason that just doesn't seem to be working.
I might be using the clip begin wrong but I can't really find any real documentation on it, all I'm doing is:
image.clipBegin(x,y,height,weight);
image.clipEnd();
I almost forgot, I'm using a scene2d Image, might be a better way to go around it but not sure what that would be.
I would appreciate any ideas on how to do this, thank you.
You want to use the OpenGL Scissor support that Libgdx exposes. See the Libgdx Clipping wiki
and the Libgdx ScissorStack documentation.
The API isn't particularly friendly (its designed to support dynamically pushing multiple constraining rectangles, which as far as I've seen, isn't used very often).
The important point to remember with the scissor stack is that it only applies to actual draw commands that get issued. Since most APIs try to batch up draw commands, this means actual drawing might not happen when it looks like it should happen. To ensure clipping is happening you must flush any buffered draws before pushing the scissor (otherwise the wrong thing might get clipped) and you must flush any draw calls before popping the scissor (otherwise things you want clipped might avoid the scissors).
See libgdx ScissorStack not working as expected or libGDX - How to clip or How to draw on just a portion of the screen with SpriteBatch in libgdx? or Making a Group hide Actors outside of its bounds.
I have a basic noob question which I'm sure many of you can easily answer.
I am finishing up a game I am making in java. It is a windowed game, and I am not using any flow layouts. In other words, I am placing the images and buttons myself using setbounds, etc. I want to port this game to android, where it will be full screen.
I have heard that I should use Eclipse or libgdx to do this. My question is, will my game still retain its dimensions on an android phone? Will it scale to a viewable size
or will I have to adjust everything on my game to make it fit?
I'm also wondering how difficult is it to port it.
Thanks for your help.
will my game still retain its dimensions on an android phone? Will it scale to a viewable size? Or will I have to adjust everything on my game to make it fit?
Yes. If you use a camera in libgdx (which you should!). It will scale everything to fit the screen, stretching it. But you can easily set it to keep aspect ratio and show black bars at the sides. For example this.
I'm wondering how difficult is it to port it.
The library is very easy to use, it depends on your current game design/implementation. But yeah, it must be very easy.
If you are not using libgdx at the moment it will be hard to port it to libgdx. May be a big part of your game has to be rewritten. But if you are allready using libgdx for the desktop version of your game you only have to handle the different input type (most times on android phones you use touch input instead of keyboard). If you are using libgdx but you are not using camera, you should definitly modify your game to use camera. By doing this you do not depend on screen aspect ration (One possible solution). Also you should then keep in mind, that on android the method pause() is called when call is incoming or homebutton is pressed and resume() is called when user returns to game. Hope this helps.
I'm making a game in Java and I have it so that when the player presses the left arrow button, three images are drawn one after the other. But when the third image is drawn, you can still see the image drawn before it (I rotated the images to make it look more realistic). Is there anyway to "undraw" the images? I've done some research and haven't found anything specific.
No, you can't undraw an image. It sounds like the images aren't fully opaque.
Not to be an over-complication junkie, but how about using OpenGL to draw them on quads. That way you can hide, show, rotate, animate, accelerate etc so much easier. And it will all be tons faster than with Swing/AWT. JOGL library + NeHe Tutorials will quickly show you how to achieve this (really, you only need this and this). Or use Unity if you wanna do it even simpler and more portable.