Tag Info

New answers tagged

0

First off 2,500 quads is only 5,000 polygons. Are you batching the tiles? The sheer number of draw calls could be causing more of a performance hit than drawing the geometry. If you would like to draw only the tiles on screen use a data structure such as a QuadTree to store the data. Here is a decent description of QuadTrees: ...


0

At first glance, it looks like you have the algorithm correct. The part that jumps out as possibly wrong is this: if(maxScore == 0){ bestMove = moves[rand.nextInt(moves.length)]; } maxScore of 0 means that the best move the AI can make will lead to no change in the relative number of pieces per player (assuming both sides continue to play correctly). ...


0

(I can't comment) so you should use a render target and do something like this. Create a rendertarget Set it to be the target for drawing Draw image one to it. Draw image two to it. Save this render target, it holds the combined images. Set the backbuffer as target for drawing.


1

First, when are you calling the jump() method? Make sure it really gets called, maybe by using a log message. Second, instead of body.setLinearVelocity(new Vector2(body.getLinearVelocity().x, 12)); you should do body.setApplyForce(new Vector2(0, 120)); Setting a velocity directly is frowned upon and should be done only in a few exceptional cases such ...


1

Collision callbacks are explained in http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Collision_Callbacks_and_Triggers. This translates quite straightforward to JBullet. However if you have already tried and failed to follow that, I'll just provide the code I have been using myself. First set-up a callback that is called on every physics ...


3

Nick already gave a more specific answer, but I get the sense from your question that you'd benefit from a more generic answer. Different platforms have various ways of getting pixels to the screen. Software is written in layers. You can implement OpenGL on top of D3D (like Microsoft has done), or even on top of GDI as software rendering (like Microsoft ...


4

Java defaults to using GDI (AWT, Swing). JavaFX supposedly will be able to make use of OpenGL in future. Java + LWJGL (an OpenGL wrapper that accesses native opengl32.dll via JNI) provides more direct hardware-accelerated support for Java. Flash Player 11 onward made use of OpenGL via Stage3D. Without using Stage3D, it is using a software renderer built to ...


0

About the place of the camera location code: If you are not using the camera in the step() function (which your probably don't), it might get updated multiple times per frame, but only get used once in the draw() function. So to prevent a waste of calculations, I'd place it in the latter. Related to the jittery camera: there is no good reason for using a ...


1

Until OpenGL 3.0, each version of OpenGL was a direct superset of the previous one, so as long as a graphics card and its drivers support the functions you use, you don't have to worry about compatibility. Also, until 3.0 was released, there was no way to choose an OpenGL version because if you got a newer version than you wanted, you just got functionality ...


0

I would suggest using KeyBindings for smooth input handling! Right now it is true you have an error in your code as stated by @Phillipp, but KeyListening is not recommended to be used in games. KeyBindings are a much newer update to Java and handle input much better that KeyListeners do. A quick Google search will provide you with more than enough sample ...


0

In your public void keyReleased(KeyEvent arg0) method you are marking all keys as released, not just the one which actually was released. The result is that when the player releases one key while still holding another, the other key will also be considered released. You need to check arg0 for the key which actually was released, just the way you already do ...


0

This is one area that I also found quite lacking. Instead of using DecalBatch, I did something much, much simpler: I added a .z value to all sprites, and just draw them in order. Technically, I created my own wrapper/subclass of Sprite with a z property which I can get and set. When drawing, I have a sorted list of sprites, and just draw them from lowest- ...


1

Keep rendering the game. just pause the logic! You can esily just attach a "pause" pass, that will render the framebuffer and then blur it or what not, and after that add some gui! should be really straight forward. The only reason i can imagine why you would like to take a screenshot is to not use all the gpu power and reduce lag when you are pausing. ...


0

If you want to resize your images, scaled to the window size, you will need to scale your Graphics object in your render method. To do this properly, you will need to make your game with a predetermined resolution (kind of like, the starting resolution of your game, that all users would start with.) Lets say you are writing a game with the window size ...


0

Here is an idea: you probably know of the dimensions of the screen, you know of the resolution of the squares, and at any time when a point on the screen is touched, you know this points x and y coordinates. int xSquare = floor(x/squareResolution) int ySquare = floor(y/squareResolution) If you store all your squares in a one dimensional array, the square ...


0

You should render stuff consecutively. Mixing up the rendering of your batch and that of the stage is not the way to do it. Especially if to consider that I am almost convinced the batch you are showing in your code and that used by the stage are two different objects. Change your code as follows: batch.begin(); gameSprite.draw(batch); batch.end(); ...


0

Relational databases and object-oriented design do not work that well together. This problem is known as the Object-relational impedance mismatch problem. One main feature of object-oriented programming is inheritence and polymorphy - entities which are similar in some regards but different in others. But a relational database has difficulties to map this, ...


1

I finally figured out how to use a matrix to do transformation on lines in Android. It's a little roundabout but hope it helps someone. The following code is to rotate a line around it's center. //coordinates of line (x1,y1) to (x2,y2) float x1,y1,x2,y2; //get the center of the line float centerX = Math.abs((x1+x2)/2); float centerY = Math.abs(y1+y2)/2; ...


1

Well what I do for my 2D game is that inside of checking before the players moves, I deal with collision after the player moves. Before I used to run into problems like yours because of the fact that when you check before hand, you stop the player from moving. Heres what you have to do, lets say that there is a block at some x, y, width and height ...


0

I assume you want to create something like a "jigsaw" puzzle. Off the top of my head, an algorithm that might get you started is as follows. Begin by splitting your image into equal pieces, it seems like the TextureRegion.split can do this for you. After this, you will have some pieces that have been split. Generate a 2D array mapping each puzzle pieces ...


0

This is typically handled with different viewports. This isn't really ideal for controls as it's not something it's designed for, but you could certainly adapt it for that without many issues. It's similar to how many split screens game work: there is one world simulation, but two different views associated with it. Viewports are supported by libGDX, as seen ...


0

To rotate them in a circular manner, you have to set your actor's origin first: image.setOrigin(image.getWidth() / 2,image.getHeight() / 2); image.addAction(Actions.rotateBy(360, .2f));


0

you can try drawing with a clipping mask, you could have a rectangle (or even irregular shapes) for the mask that represents that space. looks like LWJGL has that functionality (https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Masking). however if you want to make some kind of minimap i think @Mario sugestion is more appropriate.


2

Do not have a client talk to a database server. The client talks only to the frontend game server, and nothing else. That server then distributes client requests to the appropriate backend server. The frontend servers and (most) of all the other servers are distributed geographically. Not distributing the front-end server as in your diagram defeats almost ...


0

The trick is to read more libgdx documentation. I found that Decals work like sprites and do exactly what I want. They can be created from TextureRegions just like Sprites, and easily displayed with a DecalBatch. // Load a Texture Texture image = new Texture(Gdx.files.internal(imgPath)); // create a decal sprite sprite = Decal.newDecal(w, h, new ...


0

It seems you want to do some color keying, which Java cannot do on the fly with the Graphics2D library you are using. Due to this, you will need to create the alpha channel yourself, move to something that has color key support (SDL). Most engines nowadays do not support this operation as it is computationally expensive and you will need to do this "on the ...


2

You should be able to use glViewport() to limit rendering to a specific portion of the screen. Just keep in mind that you might have to adjust your matrixes as well. In C++, the call would be as simple as this: glViewport(left, top, width, height); You should find a wrapper for this in LWJGL as well. glScissor() would be another alternative if you don't ...


0

Your idea seems fine. A short stack of screens would let you transition into and back out of a menu without any problem. But the way you've described your problem is really odd. You plan to create a new screen instance while popping off your stack? That would defeat the purpose have having a stack of screen instances. You only need new instances when ...


0

You could store the block IDs in lines of a text file, separated by a character. For example, the text file: 0,0,0,0,0,0,0,0,0 0,1,0,1,0,1,0,1,0 1,1,1,1,1,1,1,1,1 You read it, and use the split() on every line to separate by the ',' char. Example: String row; row = reader.readLine(); String[] ids = row.split(","); for (int i = 0; i < ids.length; i++) { ...


0

Yup there are multiple ways you can go around completing this and it really depends on how you are implementing a movement system and if there's a physics engine in the game. If there is no physics engine in your game and you move only by touching squares, I would suggest you implement a future check system. Where you have a large 2d array that hold the ...


1

You should probably use texture regions. With texture regions you can select a sprite, doesn't necessarily have to be a sprite in your case, and slice it up in parts to be reused. As example: int numOfTiles_Horizontal = 3;//Can be any size as long as it lines up with the texture size. int numOfTiles_Vertical = 3;//Can be any size as long as it lines up ...


0

I use and extended OrthographicCamera to fix this. package ferret.util; import com.badlogic.gdx.graphics.OrthographicCamera; /** * OrthographicCamera that cannot go beyond specified rectangle. */ public class BoundedCamera extends OrthographicCamera { private float xmin; private float xmax; private float ymin; private float ymax; ...


1

Probably the frequency of the noise is too high. You can control the frequency by scaling the input to the noise function: float height = (float) PerlinNoise.noise(frequency * (x+offsetX), 0); You can then tweak the value as desired. Lower frequencies will produce smoother terrain, with a larger horizontal scale for the bumps. You can then adjust the ...


1

If you want to use swing, you have to run it on the EDT, so option wouldn't work. As you mentioned any long-running stuff should'nt be on the EDT and any minecraft-like game would be pretty intensive so that makes option 3 the best one. Just make sure that everything in the logic thread is threadsafe and that you use invokeLater() to do anything on the ...


1

Trust me look into Scene2D. It handles everything input related for you. You can even do timed based actions on it, which are very nice. Its also built into libGDX. Truuuuust me its super easy once you get the hang of it. Honestly, I now write everything in Scene2D. If your having issues getting started with it, Heres a little sample code for you Stage ...


1

Your Drawing constructor checks flag and starts or stops the timer. However, the only code (that you've shown) that could ever set flag is in the keyPressed callback. keyPressed is called when a key is pressed, and will modify flag appropriately, but no code will ever check flag again. The Drawing constructor already ran to completion, so unless there is ...


1

There are several steps you need to follow that will allow you to pick in a 3D application. To transform screen coordinates to world space coordinates, you need to denormalize the scree-space coordinates. Then, you need to multiply the the point of the cursor (assumed object doing the picking) in normalized device space with this matrix. Then we would ...


1

Unsure if you found an answer, but for anyone else who came here looking for one: Setting Gdx.input.setInputProcessor(stage) basically means the stage is getting all input signals. So to get your events to fire, you need to change buttonPlay.addListener(new InputListener() to stage.addListener(new InputListener() and do that for the rest of your ...


0

I got help in another part of this website on a similar question which answered this one. As such I'm going to answer my own question here and supply the answer I was given just to close this. So what I really needed was a working LookAt function, I'm still not sure what exactly was causing the problem I had before with the weird distortion other than ...


0

I read the answer by @Randomman159 and am not going to repeat what is written there. Two important tools for processing a large quantities of data in parallel are SIMD and the computation shader. These allow you to perform a lot of computation in parallel. Another tool used to improve performance with tasks that can be parallelized is multithreaded ...


1

This really depends on two things. One - Is your box axially aligned? (ie. Is there a face pointing up, down, left, right, forward and back, or is it rotated ?) Two - Are your points at all sorted? If you are using an axially aligned box, you can skip this first step. Work out a Quaternion which defines the rotation of the box. From now on, when I refer ...


1

Why don't you create a class for your coin object, and then collect all the coins in an array (Sprite[] coin), so whenever a collision occurs (player-coin), you call coins[i].destroy, where you can properly dispose all the referenced resources, or reset position for the next coin ? For drawing : for (int i = 0; i <= quantity of coins; i++) { ...


0

Interleaved VBOs Let's assume you have vertices V_1, V_2, ... V_i each having position p and normal n. Positions and normals are called vertex attributes. Vertex attributes can be stored in an array, e.g. positions = {p_1, p_2, ..., p_i} and normals = {n_1, n_2, ..., n_i}. If you feed these arrays to OpenGL, you are using non-interleaved VBOs. You can also ...


2

Read the wiki! Controllers connects/disconnects don't give listener events (right now), so controllers must be polled manually. The wiki says controller listeners don't work on the desktop for connects or disconnects. I'm no expert, I've just been reading the wiki in detail, but it looks to me like you must poll the controllers manually. This code will ...


1

I finally got it !! package com.Main; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GLCommon; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import ...


4

What you are looking for can be found in this very good explanation: http://www.songho.ca/opengl/gl_transform.html But since I found it sort of confusing without hand holding I will try to explain it here. At this point you need to consider 5 coordinate systems and how they relate to each other. These are the window coordinates, the normalized device ...


0

This code makes you draw a shape (line) whenever a touch-event is registred. package com.Main; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GLCommon; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import ...


5

It's definitely possible, you would just need to create a thin layer wrapping the Steam SDK (or part of it) to java via the Java Native Interface I'm not aware of any efforts to have an opensource library for this.


0

Before using the coordinates of your touch event, you need to scale them to your camera dimentions. You can try this code : OrthographicCamera cam; Sprite sprite; // your sprite Vector3 touchPos; // creates a vector3 object for our touch event touchPos = new Vector3(); cam = new OrthographicCamera(); cam.setToOrtho(true, 250, 120); public void ...


0

I had similar problem with zoomed in rendering. I assume by "Box2D" render you mean Box2D debug renderer. Well, here is your problem. Before rendering debug data of Box2D, transform camera accordingly (add 0.5 or whatever, as you said) and after rendering Box2D debug stuff do the inverse transformation (subtract 0.5). I hope I understood your problem and my ...



Top 50 recent answers are included