New answers tagged

1

The screen coords go from {-1,-1} to {1,1} but you are most likely feeding it {0,0} to {1,1} - hence the fact that only one-quarter of the screen gets rendered. So just to be clear - point {0,0} is not the top-left (or bottom-left, depending on your co-ordinate system) point; it's the center. This also explains the texture coord tranformation that you are ...


0

My guess is that you have a stray ! in your code. Remove the ! in: if (!Gdx.input.isTouched()) { This is making it so shootToward() is being called when the player is not touching the screen.


0

I would suggest having a look at this page and using a viewport to manage both cameras. Since you don't want scaling a ScreenViewport would be the way to go. https://github.com/libgdx/libgdx/wiki/Viewports // These would be the cameras you have set up which are following the players Camera playerOneCamera; Camera playerTwoCamera; ScreenViewport ...


0

The InputProcessor interface has touchDown() and touchUp() methods. Create a class that implements the InputProcessor interface and then give it to libgdx via MyInputProcessor inputProcessor = new MyInputProcessor(); Gdx.input.setInputProcessor(inputProcessor); I thought I should also note that if you are using scene2d and you want to react only when a ...


1

If you want to use sqlite with libGdx you can use opensource project gdx-sqlite . gdx-sqlite is a cross-platform Libgdx extension for SQLite database handling. The extension abstracts database handling to provide a unified method to handle database transacitons across multiple platforms while also adding SQLite support for desktop version of Libgdx ...


0

To move Camera in TiledMap bounds, OrthogonalTiledMapRenderer was used. I have also noticed it behaves unexpectedly: while Camera reaches map bounds, tiled map, like by inertia, moves some pixels too far (it depends on the velocity of the swipe). As a solution, on each Camera movement, Camera is forcibly put in map bounds. See putInMapBounds() method. To ...


0

I recommend you look into how box2D works. Anyways use one of the below, most likely BeginContact. void BeginContact(b2Contact* contact); void EndContact(b2Contact* contact); Excerpt from the from the greatest source of Box2d knowledge know to mankind to explain why. iforce2d.com: Anatomy of a collision Impact 1, 2, 3 When fixtures are ...


2

You can store the values in a database,It is simple if you use database like sqlite but that wont work with libgdx -android. Instead you can use gdx-sqlite gdx-sqlite is a cross-platform Libgdx extension for SQLite database handling. The extension abstracts databse handling to provide a unified method to handle database transacitons across multiple ...


1

The difference between ScreenSize and WorldSize is part of the brilliance of graphics systems like OpenGL. ScreenSize is the actual size of the window in pixels. When the user grabs the window handles and resizes the window, then ScreenSize will change. WorldSize is the size of your game level or "World". It is completely arbitrary. In a 2D game, 1 unit in ...


-1

It is very easy to resolve. Step-1: select whole project >right click> gradle >Refresh Dependency Step-2: right click on error > Fix Project Setup you are done!


0

There are some pretty good suggestions in the other answers here. I would like to add one that is more libgdx specific (so you hopefully don't have to reinvent the wheel). BitmapFonts in libgdx are raster(bitmap) images and will pixelate just like any other raster image when scaled. The solution that I usually use is that if I want a font in different ...


0

It looks like you are interpolating your own player, this is not what you want to do. At this point it is not interpolation even, but extrapolation, that is we are guessing where another player went based on their previous path. Interpolation can be though of as increasing resolution of movement in this case, but please reference better sources than myself. ...


3

If you're definitely only ever going to have one instance of these objects, and presumably you are, then this would be a better way to go. However, maybe a better solution would be to use the Singleton pattern, and (for example) create a static GetScreen() method in the Screen class that any other class can call to obtain the single instance of the Screen ...


0

In general you need two textures, an up and a down to be displayed. Then you need to check to see if the touch coordinates is in bounds. Something like the below should work for your needs with little modification: public class MyButton { private Texture imgUp; private Texture imgDown; private Rectangle bounds; public MyButton(Texture ...


1

The nice thing about the Factory pattern is that the base class can be abstract and you can have different derived Factory classes. That means you can have an ExplosionFactory, a BulletFactory, an EnemyFactory and so on, which all inherit from the basic class GameObjectFactory. Any code which is common to all objects would be in the GameObjectFactory while ...


-1

Here is the code I use to get the angle of a 2d vector, hopefully it is what your are looking for. (using our own library functions, most of which should be obvious) float zVec2f::getAngle () const { //straight up, 0.0f degrees zVec2f up(0.0f, -1.0f); //angle between up vector and our vector zVec2f normal = *this; if ( ...


0

I solved my problem by using Intersector.intersectLines method. Basically the first line is the segment between object and screen center. Then i use an if else to check which side of the screen rectangle is intersecting the first segment. Too bad that Intersector class doesn't have this method! Storwind's answer Intersector.intersectRayBounds seemed ok, ...


9

It won't hurt performance. It might in fact be (very, very negligible) faster because you save the overhead of passing these objects to the game objects. The reason static classes are often frowned upon is that their static properties are global variables and globals cause all kinds of problems architecture-wise. For example, when you ever decide you might ...


1

Did you clear the screen? You have to use glClear() method to clear the screen before drawing the current frame. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Hope this helps.


0

You will have to use signed distance field font rendering. The generated font's pixels represents the distance from the edge rather than the opacity. Where 0.5 (0x7F) is the edge of the font, 0.0 (0x00) is the outside, 1.0 (0xFF) is the inside. How wide this extends is up to you, in the grey scale example image I'm using a 2-pixel distance so it reaches ...


0

You could avoid the blur effect when upscaling by using a high-resolution image font and drawing it downscaled. Example: if your font is supposed to be drawn with a 24px size, use a sample at 48px and draw the text with a scale ratio of 0.5, because downscaling won't make aliasing noticeable. This does work fine as long as your font image strip doesn't take ...


1

I assume that you are calling update() once every frame, before you draw the frame. Your problem is that you are doing either the collision correction or the movement every frame. You need to do both. What's happening is: Your character checks if it is below the screen bounds, it isn't So it moves below the screen bounds, draws for one frame below the ...


0

The libGDX TextField is, according tho the API specification, a "A single-line text input field.". That's why it's not wrapping the text.


0

Maybe setscreen causes a device reset, in which case things get properly nullified. Two suggestions: Use windowed mode only, then you can place the window in any screen (and for "fullscreen", use a borderless, captionless window with size = physical full screen dimension, place it at any screen's origin). Render (hidden) everything to a surface first, then ...


1

Ok, after 4 hours of searching finally I found the mistake. Problem was with the sprite origin. Here's the line that was necessary (staticBody is the body around other bodies will rotate) tmpSprite.setOrigin(staticBody.getPosition().x / 32 + tmpSprite.getWidth() / 2, staticBody.getPosition().y / 32 + tmpSprite.getHeight() / 2); And here's ...


0

I did it! Yay, I'm so proud! :P Ofc I didn't stopped to google, and I found my answer in a depth buffer. What I'm currently doing is the following stuff Gdx.gl.glClearDepthf(1f); Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT); //1. set the function to LESS Gdx.gl.glDepthFunc(GL20.GL_LESS); //2. enable depth writing ...


1

Boolean fullScreen = Gdx.graphics.isFullscreen(); Graphics.DisplayMode currentMode = Gdx.graphics.getDisplayMode(); if (fullScreen == true) Gdx.graphics.setWindowedMode(currentMode.width, currentMode.height); else Gdx.graphics.setFullscreenMode(currentMode);


0

You should check that your spritesheet is power of two. for example: 3 tiles of 64x64 = one spritesheet of 192x64 ---> wrong 4 tiles of 64x64 = one spritesheet of 256x64 ---> right Even if each sprite is power of two itself. I hope this helps you.


0

According to LibGDX documentation, it does this for you: intersectRayBounds public static boolean intersectRayBounds(Ray ray, BoundingBox box, Vector3 intersection) Intersects a Ray and a BoundingBox, returning the intersection point in intersection. This intersection is ...


0

Depending on what program you are using, a simple draw line command would be the simplest of ways. To provide the user with more target info, use the following. P1x=230; P1y=120; P2x=20; P2y=40; Bearing=atan(No/Ea)*180/Pi; Distance=sqrt((P1x-P2x)^2+(P1y-P2y)^2);


1

I needed to do the same thing and went for an extremely simple solution in the end and it seems to work well. I created my own StageExtension class that extends Stage (for other reasons), but within this I simply override the touchDown method adding 2 lines; @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { ...


0

We have two cases, the first case being your ball is not colliding. Because of Newtons First Law your ball will have the originally random assigned velocity, \vec{v_{i}}. The second case is the one we are interested which is collision. Assuming we are operating in 2 dimensions then we can treat walls and edges of boxes as line segments. Using our current ...


0

The problem was in this line. TextureRegion tmp = new TextureRegion(Asset.sprites, SPRITE_SIZE * SPRITE_COUNT, rand * SPRITE_SIZE); I've used the wrong params, so I forgot width and height. I changed to this. TextureRegion tmp = new TextureRegion(Asset.sprites, 0, rand * SPRITE_SIZE, SPRITE_SIZE*SPRITE_COUNT, SPRITE_SIZE);


0

I already solved my problem using this: viewport.getWorldWidth() I can't explain more because my english is so bad


0

I solved my problem using steering behaviours thanks to the suggestion by @Alexandre Vaillancourt. The "arrive" behaviour was the solution for me as suggested in his comment.


0

This can be done in a simple 3 step looped process. Step1: Clear screen of all moving objects or sprites Step2: Apply formula -- Height-(9.8)*T^2 Step3: Apply objects or sprites in new position I even made you quick graph to show you what I mean. https://www.desmos.com/calculator/f0bglhnjjg


2

The parameters control which axis the image will be flipped around; sometimes you only want to flip around one or the other axis, instead of both. The first parameter, if true, causes the image to be flipped in the X direction (horizontal flip) The second parameter, if true, causes the image to be flipped in the Y direction (vertical flip). If both are ...


0

After researching LibGDX and OpenGL further I've found the root of the problem, which was loss of OpenGL Context. All of the texture loading needs to be done when the thread has access to the context, which is true when the app first loads but becomes false later on. In order to fix the problem, the textures need to be loaded in a thread that has access to ...


0

Unfortunately, you usually have to write these json files by hand. The syntax isn't too awful. To style an object its usually <fullyQualifiedUIWidgetName>$<StyleClassName>:{ <styleName>: { <styleParameter>: <value>, <styleParameter>: <value>, }, <styleName>: { ...


1

I can't speak for Google play services, but between the embedded LibGDX networking and Kryonet, I would suggest Kryonet. After all, it was written partially by the authors of Libgdx :) . It's also a big plus that you can integrate kryonet using gradle. By "Libgdx's embedded networking" I assume you mean the sockets that Libgdx provides. Kryonet handles all ...


0

It seems that you are rotating your actor with the rotateTo action, but your sprite, which is doing the actual drawing, knows nothing about the actor's rotation. Try sprite.setRotation(this.getRotation()) in your draw() code.



Top 50 recent answers are included