New answers tagged

-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

Just render the image on your JFrame/JPanel using g.drawImage(img, x, y, width, height, obs) with this trick: JPanel panel = ...; // Your target panel Graphics g = ...; // The graphics object of this panel (argument of paintComponent) float scale = Math.min((float) panel.getWidth() / i.getWidth(), (float) panel.getHeight() / i.getHeight()); int ...


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 ...


0

The problem is your multiplication code. When you do: m00 = m00 * matrix.m00 + m10 * matrix.m01 + m20 * matrix.m02 + m30 * matrix.m03; You change m00, so you are not allowed to reuse it later in that function. Same for m01 and all the other ones. Use temporary values instead: float temp_m00 = m00 * matrix.m00 + m10 * matrix.m01 + m20 * matrix.m02 + m30 * ...


0

Your z rotation is messed up, it should be negative at (0; 1), and positive at (1; 0)


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 ( ...


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 ...


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 don't know android specifically, but if you are using OpenGL ES, you can use a shader to make this work. First create a image like this in black color. Then use a color tint. Now use a fragment shader to draw this texture. The code looks like this. #ifdef GL_ES precision mediump float; #endif varying vec2 texCoords; uniform vec4 color; uniform ...


1

Your whole matrix is incorrect. For example, this is one of the ways it should look like: So, in code: dest.m00 = 1.0f / (tanHalfFOV * aspectRatio); dest.m10 = 0; dest.m20 = 0; dest.m30 = 0; dest.m01 = 0; dest.m11 = 1.0f / tanHalfFOV; dest.m21 = 0; dest.m31 = 0; dest.m02 = 0; dest.m12 = 0; dest.m22 = -(far + near) / range; dest.m32 = -2 * far * near / ...


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 ...


4

I use the libGdx Json functionality to save my game state to JSON; public class GameInstance { //Some fields, constructors, utilities public void saveState(GameState state) { String save = json.prettyPrint(state); //Save to the file using FileHandle } public void loadState(FileHandle file) { String ...


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

I found my issue after getting some sleep, I forgot to take care of the parents in the CollisionComponent. All I had to do is to iterate up in the entity heirarchy chain (scene graph nodes) and apply the parent transforms to the polygon. // Get some temporary Vector objects to work from the object pool Vector2 tPosition = Vector2.REUSABLE_STACK.pop(); ...


0

Treat all the chunks around player, as offsets (shown in one axis but applies for both): -3 -2 -1 0 +1 +2 +3 <- 7 offsets for 1 axis; for x * y that would be 49 offsets. 0, 0 is the offset where the player is - the origin of "player space". 3, -2 might be roughly to the northeast or whatever, depending on your coordinate system setup, and so forth. Now ...


1

This is the while loop above redone. Kind of ugly and repetitive but it works. I had to use Math.floor and Math.ceil to solve the collision issues which is due to precision I guess. Any spare dt left over if the action sequence is finished is discarded so that might be something to save for accuracy but the timesteps are really small so it may not be ...


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

I am not exactly sure what your problem is. Did you place the pos.X + 1 in the proper place. Could you edit to show the object? Then maybe your problem could be solved. For a start, you should check where you placed all your objects and everything. That is were the errors usually come.


1

Math.cos uses radians, not degrees. You want to go from 0 to 2* Math.PI You could do that like this: if (Keyboard.isKeyDown(Keyboard.KEY_D)) { if (i < 360) { //Convert to radians by multiplying by Math.PI*2f/360f float theta = Math.PI * 2f * (float) i / 360f; setX((float) (groundState.getX() + groundState.getRadius() * ...


0

In onAdClosed() you need to check if the user has watched the ad. public void onAdClosed() { if(adFinishedPlaying()) { giveUserPoint(); } } }


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

BufferedImage tileSheet = loader.load("tiles.png"); BufferedImage temp = ImageIO.read(getClass().getResource(path)); The file "tiles.png" is not in the correct position, and thus it cannot be loaded as it equals null.


2

Yes. For 2D sprite-based games, AWT can be used to handle the rendering to great effect. It can even be hardware accelerated, depending on the available hardware. Without any code or detailed profiling snippets, it's hard to say what the issue is. Best I can do is offer some basic tips for working with Java and AWT when building games. Working with the ...


0

Get vec2 from start point to target point (mouse coords in world space). Set b2body velocity to normalized version of that vec2, multiplied by your desired speed. Keep stepping - velocity will carry you closer to target point each time. On each step, if distance from current point to target point (magnitude) is less than velocity, set b2body position to the ...


1

function newLevel() { if (ModPE.readData("firstLaunch") != true) { ModPe.saveData("firstLaunch", true); clientMessage("This is the first launch"); } else { clientMessage("This is not the first launch"); } }


2

I had the same problem while searching for funnel algorithm. Here it is a summarized procedure, considering one origin and target point: Triangulate your polygon Select origin and target points find origin and target triangles Do any graph search algorithm to find the path of triangles from origin to target find the path of edges connecting the triangles ...


0

The easiest thing you can do is, for example, % the actual time. actualtime %= MAX_TIME; Very easy method!


0

My first thought If I understood correclty, you wants it to repeat the time as in a cycle, so you have a "class" which handles time by using modulus. //I don't know how to write it on Java class TimeHandler = { var current = 0; const max = 200; update() => { // it will make "current" eventually become 0 again current = (1 + ...



Top 50 recent answers are included