i'm learning libgdx in purpose of building a realtime multiplayer painting game. Game will last in 120 second and 4 people with 4 different colors will race to paint more portion of the screen.
Now i'm trying to implement circular painting as player moves. As i made some researches, i saw that i can use pixmaps to implement such behaviour. As game updates, i will fill a circle at players x and y with radius r and draw a texture that scales the screen from pixmap( which is also game map). Is there a better way to achieve this?
And i must make it for all resolutions. 1024X1024 resolution versus 240x240 must be able to play. Can i do this by using lowest resolution pixmap and drawing a scaled texture from it? Thank you...
Thats the game im trying to do..
https://www.youtube.com/watch?v=EU8Eyh0tZOo&t=270s
You need to use Framebuffer for this kind of game. Pixmap is extremely slow for using every frame.
https://github.com/mattdesl/lwjgl-basics/wiki/framebufferobjects
And yes you can make all resolutions play together like this.
Related
In short, I'm making a simulation where I have a bunch of creatures that can see each other. The way I want to do this is to capture an area around each creature and give it to their neural network, and make them evolve to recognize their surroundings. I am coding this using LibGDX, and I don't plan on making screenshots every single frame because I can imagine that that is already a very poor idea. However, the problem is that I don't know how to get the pixels inside a defined square without capturing the entire screen and then cherry picking what I want for each creature, which will cause a MASSIVE lag spike, since the area these creatures will be in is 2000x2000, and therefore 12 million different values (4 million RGB values).
Each creature is about 5 pixels (width and height), so my idea is to give them a 16x16 area around them, which is why iterating through the entire frame buffer won't work, it would pointlessly iterate through millions of values before finding the ones I asked for.
I would also need to be able to take pictures outside of the screen (as in, the part outside the window's boundaries), if that is even possible.
How can I achieve this? I'm aiming for performance, but I do not mind distributing the load between multiple frames or even multithreading.
The problem is you can't query pixels in a framebuffer.
You can capture a texture from a framebuffer, and you can convert a texture to a pixmap.
libgdx TextureRegion to Pixmap
You can then getPixel(int x, int y) against the pixmap.
However, maybe going the other way would be better.
Start with a pixmap, work with the pixmap, and for each frame convert the pixmap to a texture and render that texture fullscreen. This also removes the need for the creatures environment to match the screen resolution (although you could still set it up like that).
I'm new to the game development and I'm trying to code 2D RPG game. im using png images to create objcts and move around. So it is pretty easy to detect collision between rectngles and other simple shapes like this.
if(object1.collides(object2)){
}
what is best way to detect collision of image objects like player, or npc?
The most common way is to create a hitbox that is the approximate shape of your object. The hitbox can be very simple like a rectangle or circle around your object, which is actually invisible.
Have a look at this example, the black box is the hitbox of Mario and you only need to check its boundaries:
But if you really need precision, then you will need to go through the pixels of an image and create the custom polygon. However, the more complex your polygon is, the harder it is to detect collision. Most of the time, game developers rely on physics engines to deal with it.
I've made an Asteroids game and am having trouble with different screen sizes. Yes, I know about viewports but in my case I don't think that can work. I've tried to use it but my objects are not images. Instead they're rendered by a ShapeRenderer and therefore the viewports probably not affect them I guess. I've solved how to fit the text for most types of smartphone screens but not the rendered objects like the player and asteroids. On some screens they're perfect size and other screens either too small or too big.
Is there a way to scale rendered (ShapeRenderer) types in libGDX so that they will fit the screen size / resolution? Or must I try to implement a class for common resolutions that can be used?
Here is two pictures that illustrates the problem. The text in the images are aldready fixed by the way.
EDIT:
It does work to create and apply the viewport for the ShapeRenderer now, but I'm still having the same problem. The game objects inside the viewport aren't scaled to fit the current screen. I need a way to scale down the game objects s using a viewport (if possible). The way the game is going to be implemented is that the size of the smartphone screen is the game world size. Therefore, there are little space to move the ship if the screen is pretty small. I want the objects to be moving around in an area that fits the viewport size. The game should not get more difficult or easier depending on the screen size.
Example on left: The game on a large smartphone screen
Example on right: The ShapeRenderer viewport is working
Viewports were created in order to reduce the effort needed to render on different sized screens. So are ideal for situations like this.
In order to use a Viewport with a ShapeRenerer you simply need to set the ShapeRenderer's projection matrix to the one in the viewport's camera.
shapeRenderer.setProjectionMatrix(veiwport.getCamera().combined);
This means the shapeRenderer will render the way the viewport is configured.
I am currently working on a LibGDX mobile game app. The problem I am having is that I want the world width and height to be 480x480 and the screen width and height to be 640x480. The extra 240 units on the screen would be used for rendering UI, kind of like in ROTMG or Clash Royale(The cards view while in game).
I have thought about rendering the UI over the game with another camera, but it is not the design style I am going for. I want the game's logic and coordinates to be within the world's width and height and not take in the extra space for UI.
How would I do this?
P.S. the game is 2d
P.P.S. I would like for the game to keep this config on resize.
Denfeet, create a fullscreen Stage with 2 Group instances - one of them for UI, the other for the game. Groups: Game's bounds are 0, 0, 480, 480. UI's bounds are 480, 0, 240, 480. Now if you want to work in coordinates relative to the game Group for example, call Group.localToStageCoordinates(Vector2 localCoords) on the game Group (or make yourself a helper method so you don't have to keep writing this long name). Also the UI and game logic can stay completely separated this way - magic :-).
I always like to separate my game from UI. You can just create a camera full screen and put your UI over it with a Scene2D stage. Unless you want the exact dimensions you don't have to worry to much about positioning since you just overlay your UI elements. If you want to use a stage for your game as well then just create a 2nd stage, one for the game and one for the UI.
Anyway, looks like you are thinking in pixels. Your game does not need to know about pixels, just how much to render of your game world. If I would have a tile that is 10 x 10 units large and I want to show a square of 10x10 tiles to the player I would create a new FitViewport(100, 100) for it. The Viewport calculates world units back to pixels on the device it is running. This makes things more logical for you or anyone who works on your program. My player is not 256 pixels high because that is how hight the image is, no my player is 1,80m high and uses a image to display. If he wants to jump like a ninja he should jump over another player say 2m and he falls at 9.8m/s.
I'm making a 2D tile based game and I need to make part of a sprite transparent.
I assume I should choose a determinate color and tell Java "Please Java, don't draw any pixel of this color.", but I don't know how to do it.
I already googled it but I only get results about "alpha".
Also how can I "set priority" to my sprites so that the ones with high priority are always drawn in the front?
Thanks.
Use png files for the sprites. Java will draw transparent parts of png files transparently.
As for the sprite ordering, this is difficult to advise without any knowledge of your game's code structure. You could give each sprite a Z-index, sort and draw in order.
This KineticModel creates multiple, translucent instances of GradientImage as part of a simulation.