GDX | Game Development Extensions | Game Engine library
kandi X-RAY | GDX Summary
kandi X-RAY | GDX Summary
Game Development Extensions, a battle-tested library of game-ready high-performance C# code. Documentation available at
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of GDX
GDX Key Features
GDX Examples and Code Snippets
Community Discussions
Trending Discussions on GDX
QUESTION
Just installed libGDX & android studio yesterday. My boss wants to use libGDX & javaFX (for UI) together in a project.
My assumptions: It sounds like I can do that by using a canvas. LWJGL3 does not support a canvas backend. So i need to use the legacy LWJGL2
My question: How in an existing project do I add legacy support and the libraries?
My current compile is failing with: error: package com.badlogic.gdx.backends.lwjgl does not exist import com.badlogic.gdx.backends.lwjgl.LwjglAWTCanvas
...ANSWER
Answered 2022-Mar-23 at 00:25There are instructions here for migrating from lwjgl2 to lwjgl3, so you can follow them in reverse.
Basically, change your module's dependency from com.badlogicgames.gdx:gdx-backend-lwjgl3
to com.badlogicgames.gdx:gdx-backend-lwjgl
and change your launcher class to use LwjglApplication instead of Lwjgl3Application. The associated application configuration class works a bit differently, too. It uses public fields instead of setter methods.
QUESTION
Currently I have a game in libgdx that show ads on top of the game layout. However, as you can notice, it hides part of the top of the screen, where the score is shown.
Question: How can I make the ads show ABOVE the game view/screen, so it doesnt overlap/hides anything from the game? I want the screens to be as shown in the next picture.
Current code:
...ANSWER
Answered 2022-Jan-24 at 13:01To avoid this overlapping effect using a RelativeLayout
you can create an Ad Container
(eg: a RelativeLayout Container) to be on the top of the screen by using the RelativeLayout.ALIGN_PARENT_TOP
rule and add the GameView
below of the Ad Container using the RelativeLayout.BELOW
rule. Finally add your AdView
as a child of the above Ad Container
.
Below is an example of how you can do the above structure:
QUESTION
I've been learning about libgdx recently. In the process of following the instructions on their libgdx wiki I ran into some problems.
Specifically in the GameScreen class at the 99th line I changed the code inside so that it goes back to the previous screen (MainMenuScreen class) and yes you see when the mouse is pressed it worked (I mean go back to the screen before ) but a very very short time after, the screen AUTOMATICALLY switches to the GameScreen class (like I click the mouse once but it makes me 1 more redundant task). I guess when I click on the GameScreen screen it did the code in the if statement on line 99 to go to MainMenuScreen screen. In that screen at line 32 I guess it was true after I got to this screen because when I change the key is listened then it works fine (only converts once). I was intending to try implementing InputProcessor on each screen class but now I'm avoiding it for some reason. Can someone give me some advice recommend.Thank you
Here is the source code for the MainMenuScreen class.
...ANSWER
Answered 2022-Jan-11 at 06:29Your analysis of the problem seems correct to me. The method Gdx.input.isTouched()
will immediately return true, if the screen is still being touched after you changed to the main menu.
Also you the solution that you already tried seems correct:
I was intending to try implementing InputProcessor on each screen class
When using an InputProcessor
you will get one event (the method call to touchDown
or touchUp
) when the screen is touched, and don't need to pull the touch event using the isTouched
method.
A problem when implementing InputProcessor
with both classes probably is, that you can only set one to be the input processor of the game using the method Gdx.input.setInputProcessor
. (When setting the second input processor, the first one is removed).
A solution to this problem is the InputMultiplexer. You can add this multiplexer as the input processor of the game (using Gdx.input.setInputProcessor(multiplexer)
) and then add your input processors (the main menu and game objects) to this multiplexer: multiplexer.addProcessor(mainMenu)
or ((InputMultiplexer) Gdx.input.getInputProcessor()).addProcessor(game)
.
This way you can handle touch events instead of pulling the touched state in both of your classes.
QUESTION
I'm using libgdx scene2d to render 2d actors. Some of these actors originally included scene2d Label actors for rendering static text. The Labels work fine but drawing ~20 of them on the screen at once drops the frame rate by 10-15 frames, resulting in noticeably poor rendering while dragging.
I'm attempting to avoid the Labels by pre-drawing the text to textures, and rendering the textures as scene2d Image actors. I'm creating the texture using the code below:
...ANSWER
Answered 2021-Dec-09 at 16:16I have not tested this, but I think you can enable culling for the whole Stage by setting its root view to use a cullingArea
matching the world width and height of the viewport. I would do this in resize
after updating the Stage Viewport just in case the update affects the world width and height of the viewport.
QUESTION
Consider:
...ANSWER
Answered 2021-Oct-12 at 19:31This is the best I can do from your explanation. I think you're over-complicating how to define the regions. This matches your description. No reason to treat the last row differently than the rest.
You also should make SheetAssets
a val
instead of lateinit var
that you're redefining every time this function is called. That is leaking all your old textures and making them inaccessible.
And I used an if-statement with early return to reduce nested code. And I used getOrPut
and ?:
to eliminate some of your redundant null-assertions.
QUESTION
I'm using LibGDX to render 2d fog-of-war type functionality. This involves drawing a dark rectangle over the entire map with transparent holes in it where you can see the map below. I'm attempting to use OpenGl stencil buffer to create the circular masks, but I can't seem to get the logic correct.
The code below correctly draws the dark rectangle (the fog) but the circular masks are not being stenciled. i.e. the entire map is dark.
...ANSWER
Answered 2021-Nov-29 at 17:54One way you can achieve a fog-of-war effect is by keeping a Framebuffer
that you write transparent pixels to, and then draw that buffer ontop of your game view:
The steps are more or less:
Draw game
Update fog-of-war buffer
Draw fog-of-war ontop of the game
QUESTION
I am starting programming with Scala and I decided to make a really simple game using libgdx. I have created this class:
...ANSWER
Answered 2021-Nov-28 at 15:39Yes, Scala compiler is quite confused here, because the constructor want a gdx array, not a Java array (look at the documentation). A possible workaround could be in using var arg syntax:
QUESTION
I have this ship sprite (prototype for now) and I've been trying to move it along its rotation but it is not working so well.
<-- Vid -->
https://imgur.com/a/gd1ac7O
<-- Example Image of what I think should happen -->
When researching, I saw that sometimes the cosine is for the x position and the sine is for the y position, this makes me a little confused about what to do. But sometimes I saw otherwise which makes me wonder since I thought the x should be using sine and y should be cosine
Code:
...ANSWER
Answered 2021-Nov-11 at 17:17If you create an extra Vector2
member, direction
in your Player
class you can get libGDX to calculate the x
and y
delta by using the rotateDeg
method on Vector2
:
QUESTION
I'm working on a game, and during the initial phase I want the user to be able to switch between two/three screens freely.
From what I've seen online you switch screens by calling the setScreen function on your game instance. The problem is that it seems to work only when you pass a new instance of a screen as the parameter (I tried to pass the whole screen to A a new screen B, but calling myGame.setScreen(A) while on B doesn't do anything), and I'd like to store the changes applied by a user even after he leaves the screen.
I thought about storing these informations in a class that I'll pass as a parameter everytime the user switches screens, but this solution seems inefficient and wrong.
Is there any standard way to return to a previous screen without losing all the changes done to it? Does myGame.setScreen work only on new instances of Screen?
Here's the code I tried to use to return to the old screen :
...ANSWER
Answered 2021-Oct-30 at 11:40According to your code you are passing the gameScreen
to constructor but not initializing the class variable. Therefore when calling game.setScreen(gameScreen);
you are passing null
instead of the actual screen instance.
To make your code work just initialize your class variable in constructor.
QUESTION
Does anyone know why libGdx can't find the .tsx file? I have have tmx tsx and png in the assets folder under the core folder. In the tmx file, I have the source set to the file path for the tsx file. I made the tsx and tmx file with Tiled if that helps.
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: Maps in use\tileset_gutter.tsx (Internal)
...ANSWER
Answered 2021-Oct-26 at 04:17If you don't qualify the file reference then it assumes the root folder to be assets
in the android project as works with everything.
Howeover, you can get the FileHandle
of files in the core project with
Gdx.files.internal("data/...
. (where data
is a folder in core/assets
which should be where yours are)
You can switch between how TmxMapLoader
resolves the files, to delegate the FileResolver
of TmxMapLoader
to this internal handler would be.
new TmxMapHolder(new InternalFileHandleResolver())
which delegates to the internal storage location.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install GDX
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page