Tag Info

Hot answers tagged

8

TextureAtlas#findRegion(String) returns a region with a name that matches the name specified. It does not copy the region, therefore any changes you make to the region will be reflected in the TextureAtlas. To overcome this issue, simply instantiate a new TextureRegion object and pass it the region found inside your TextureAtlas: background1 = new ...


3

In the second case it is not drawing because the constructor with no arguments doesn't set a width and height for the image, however the constructor that takes the drawable obtains the values from it. To fix in your case: Texture texture = new Texture(Gdx.files.internal("cookie.png")); Image itemImage = new Image(); itemImage.setPosition(10, 10); ...


3

If you would follow the second strategy, changes made to the Vector that got passed as parameter "v" will also be made to "vector2", since they are the same object. You should have a look at this question: http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value In Java every object is an reference, so you need to copy, for ...


2

Given credit to Alan Wolfe for what he said on "INFINITELY tile". A 2d perlin noise (or a 2d simple noise) will have no seam problem as far as you stay away from noise borders (defined by floatin point dimenision) Referencing the image: and said that you have chunks with 128X128 vertex, in chunk i,j you compute each vertex as : for x : 0 .. 128-1 for y ...


2

You can use pendulum physic to approximate your rope swing. Calculate the fluctuation period (this is true for small fluctuations) T = 2*PI*SQRT(L/g) where: PI = 3.14 g = 9.8 (if I remember) the earth gravity acceleration L : the rope length, or better the length from rotation fulcrum to the character hands. Then you get the fluctuation angle as ...


2

Two very general suggestions -- Often in board games a good human player runs through a list of rules or if-this-then-that mentally. If you can understand what a good human player in your game would do, then it's just a matter of translating that into code. This is generally referred to as "rules-based AI". If the game is strategically simple, then ...


2

A lot of great Libgdx extensions have been added to the maven repository such as freetype, tools and many other great libraries. This means you can add extensions in a blink of an eye, at least if you used the gradle LibGDX setup. In your case you want to add freetype, look it up in the link above and select the version you need. Now select the tab Gradle ...


2

As mentioned above, you can start and stop a SpriteBatch in the same draw-method, also for transparency you need to enable BLEND. Here's what I did with one of my UIs. batchstuff... spriteBatch.end(); Gdx.graphics.getGL20().glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); ...


2

I found the solution, so I think I should write here for other ones later. First I download the source code of box2dlights. Then open BaseLight.java and find "segments" member variable. This variable contains all information about what I was finding. This code below is just for debugging purpose: rayHandler.setCombinedMatrix(camera.combined); ...


2

Box2D has a Java library. It might be a bit more than you need but it's pretty robust and used in all sorts of projects. Maybe someone else can recommend a better library solely for collision detection. If you want to roll your own solution, which would probably be better if you want to keep it simple, you'll need to look into Oriented Bounding Box (OBB) ...


2

What is the problem? Generally speaking, you want to do a topological sorting, where the nodes are your bricks and the edges mean "is this node behind that other node" relationship. So all you need to do in order to sort anything anywhere is to decide on "is behind" relationship. It seems that your code treats bricks as uniform objects in a grid, ...


1

I personally never calculate an angle like that. I like to work with vectors, it might be slightly less efficient but this way you can do it step by step, it gets more readable and easier to understand. So what is a vector? A vector is essentially a direction and a magnitude together. Often in games it is used as a position data structure too but ...


1

for (int i = 0; i < vertices.length / 3; i++) { vertexList[indices[i]] = new Vector3f(vertices[i], vertices[i + 1], vertices[i + 2]); } In your first run, you're taking vertices[0], vertices[1] and vertices[2], in your second run you're taking vertices[1], vertices[2] and vertices[3], see where the problem is? And i don't get why you're using ...


1

I hope I am understanding your question correctly -- if not let me know. I believe the following is where you are unprojecting the coordinates: @Override public boolean mouseMoved(int screenX, int screenY) { worldCoordinates = camera.unproject(new Vector3(screenX, screenY, 0)); return true; } Because you are using a viewport, you must add the ...


1

One option is to give the Wolf class a disguise function. This could look something like this. class Wolf { void disguise(Animation p_target) { this.animation = p_target; } void animate() { play(this.animation); } void reveal() { play(this.animation.reveal); } } Another option is to create a child ...


1

at the base of some perlin noise implememntatio there's a perturbation array private static int[] p = {151,160,137,91,90,15, 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, 88,237,149,56,87,174,20,125,136,171,168, ...


1

The glGenVertexArrays() interface was added to OpenGL core contexts in version 3.0, the same version in which immediate mode rendering was removed from OpenGL (although it had long since been deprecated, 3.0 is where it finally absolutely went away) So you are correct. If immediate mode drawing works, then you are using an OpenGL context old enough that ...


1

As Menno Gouw mentioned, you could use a noise function although you can actually use any PRNG. You will need to seed it every frame though, based off some predictable, relative value, such as the player position. If the player only moves horizontally, then this is simple. seed = player.x I don't suggest a noise algorithm in this case, since the ...


1

In Java you can not have a class that is inherited from more than one super class. you better use Interfaces, because you can use more many implemented Interfaces. Interfaces are objects similar to classes. in Interfaces you can have variables and and methods, nut defining and giving values to methods and variables should be done in the class that ...


1

In the first function, the division will be integer division and the result of the division will be casted to double. It is thus equivalent of return (double)(System.nanoTime() / 1000000000); So for example if the System.nanoTime() gives a value of 142154, the getTime() will return 0, because in integer division the fractions are ignored. 142154 / ...


1

Below code works for me, I get the message when pressing the back button. if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)) { Gdx.app.log("Debug", "Back pressed!"); } Are you calling below method before the one above? Gdx.input.setCatchBackKey(true);


1

tl;dr: NO. Long answer: As @LarsViklund pointed out, you will have significant trouble using multiple threads to render. OpenGl is kinda bad at multithreading, so don't. If your rendering is slow it's not because of slow OpenGL calls. Your architecture is just bad. You can improve it by moving away all your logic (UI events, physics, AI,...) from your ...


1

An OpenGL context may be current on at most one thread at a time. If you make a context current in one thread, it will be made uncurrent in the previous thread. So while you can migrate contexts between threads, you can not do so in any concurrent manner. While there is the existence of shared contexts and shared resources, those are not exactly in the fast ...


1

There was something wrong with my collisionNormal method, where the left and right vectors were actually flipped. This made collisions along the x axis actually push the objects into each other. if (wy > hx) { if (wy > -hx) { /* collision at the top */ return new Vec2D(0, -1); } else { /* on the left */ return ...


1

LibGDX is formally a Framework and does implement the game loop for you. getDeltaTime() does smooth out over a number of frames. Instead you could use getRawDeltaTime(). I have seen some people get smoother results by capping the framerate to 30/60 instead of using getDeltaTime.


1

The following answer gives the angle from horizontal. (http://stackoverflow.com/questions/7586063/how-to-calculate-the-angle-between-a-line-and-the-horizontal-axis) (This will boil down to essentially using the same info David van Brink provided in his comment.) You might want one that works from the current angle of the ship. Unless the rotation is ...


1

Yes, libGDX does optimize in that area, but that is irrelevant to the code you've written here. In your first part where you drew off-screen, you went and drew off to position 50000 that would be taxing to the computer, but the fact of the matter is that your Gdx.graphics.getWidth() / Gdx.graphics.getHeight() is unlikely to be ever 50000 unless you are ...


1

Swing should be fine for your needs. You should check out this stackexchange for other possible problems with Swing.



Only top voted, non community-wiki answers of a minimum length are eligible