Tag Info

New answers tagged

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


0

I can't help you exactly with code because I'm not sure where all your variables are coming from. If you provide some context to this code, I can help more specifically. In the meantime, take a look at this picture: If you know how far you want the sprite to travel, and you know the angle. You can calculate the x and y distances using the formulas from ...


0

I would suggest just making the image with a glowing effect, but if you must have it done in game then you would: 1) Render your scene or "glow objects" to texture A 2) Bind texture A, then using the horizontal shader, render a quad to texture B 3) Bind texture B, then using the vertical shader, render a quad to texture A However This requires the ...


0

Have you consider using chunk of pixel in your second point to get better performance? If you search for a different aproach you can investigate Cellular automaton , starting from lights chunk for each neighbour lite them according to distance and material repeat for its neighbours ...


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


0

You need to add the correct JARs to your project. For example, you can see from this Gradle/Maven repository search that there are both gdx-freetype and gdx-freetype-platform JARs. To add them to Gradle, you just need to add the dependency name and version under the dependencies section.


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


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


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


0

You need something like perlin or simplex noise. This will always generate the same noise based on position with a certain seed. Now you can add stars where the noise is a certain level. Simplex and perlin noise always create the same noise based on location and seed. So if you would create a noise ranging from 0 to 255 you could generate a stars at a ...


0

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


0

You're assumption that you do not need any physics is wrong, anytime you are dealing with moving objects in 1D, 2D, 3D... environments and you need to detect if two objects will collide then you are doing physics calculations. You can not get away from it. Returning true or false is easy, but figuring out if a collision has happened or not can range from ...


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


0

Just store the position in the entity object as well. For dynamic objects I am using both arrays and I store the position of the object inside the object as well for various reasons. One reason is to use the array for drawing, if I only want to draw from coordinate (10,10) to (26, 19) because my screen does not reach the others anyway I can use the various ...


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


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


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


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


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


0

My understanding is that the goal is to have a background "high quality render" while still updating an on-screen progress bar and eventually producing a still image from the background process. The easiest way to do this will probably involve having two separate OpenGL contexts, each set as 'current' on one thread. The first one renders your progress bar ...


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


0

Alternatively, you can break up your long, slow render parts to intersperse with your UI updates. Slow part takes too long? Break it into multiple draws. Each draw is still too long? Fill a smaller area. It might be a little bit inside out, but it's a way to do it all in one thread.


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.


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


0

Yes, it's perfectly acceptable to use g.drawImage(); to render your bitmaps. Most of the optimization you'll be doing is cutting down on the number of times you call that method, rather than using some other method entirely. For example, you might only clear the parts of the background that have changed ("dirty rectangles") and draw the changed parts over ...


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


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


0

Here's a quick mock up demonstration of vector mathematics in action: https://dl.dropboxusercontent.com/u/38185080/Flash/Examples/Vector%20Mathematics.swf Click to move. Following on from my answer to your previous question here, and applying what @Frank and @David have explained, you can retrieve the angle of rotation by calculating the inverse tangent ...


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


0

About textures loading, yes i suggest you to make them static in the AssetManager class and then declaring them in the "level" class with Texture letterA = AssetManager.letterA and so on. Same goes for the dictionary (i never had to process a .txt file so i don't know if you're going to declare it as a String or else..). I usually make static every asset ...


0

Here's why you probably don't want to use a rounded rectangle to try to fix your problem: Now, getting stuck on the edge like that is probably just as frustrating, if not more, than not being able to move right at all. I think you probably want to employ some error correction when you move. What I mean is, when your character moves, let's say, right, if ...


0

I'm going to explain this using Vector mathematics. I would also recommend to store your x and y values as such, as it makes it easier to maintain. Here's an example: public class Vector2 { public float x; public float y; public Vector2(float x, float y) { this.x = x; this.y = y; } public static float length(float x, ...


0

What you need to do is keep track of what distance or what percent the image has traveled down the path, and increase that amount by a small amount (based on your frame rate) in your update function. When you want the image to start moving from start to end, you might set a percent variable to zero. Then, in your update you might say: percent = percent + ...


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


0

As far as I am aware, the setting genMipMap for TextureAtlas is not available. If you're packing your images using TexturePacker to create your atlas, you can pass it Settings: TexturePacker.Settings settings = new TexturePacker.Settings(); settings.combineSubdirectories = true; settings.filterMin = Texture.TextureFilter.MipMapNearestLinear; ...


0

Check whether it's possible to draw your objects or not when they are out of screen. if(yourSprite.x>screenWidth || yourSprite.x+yourSprite.width<0 || yourSprite.y>screeenHeight || yourSprite.y+yourSprite.Height<0){ //Don't draw } else{ //Draw your sprite } And easily can find whether your sprite is behind of another object or not ...


0

In response to Kelly, I too have very similar code and have tried to apply the checking loop as described above: for (int i = enemies.size() - 1; i >= 0; i--) { Enemy enemy = enemies[i]; for (int j = bullets.size() - 1; j >= 0; j--) { Bullet bullet = bullets[j]; if(enemy.getBounds().overlaps(bullet.getBounds())) { ...


-1

I would not recommend this! Games are games and GUIs are GUIs. Just because they're not console applications does not mean that they're equivalent. I'd HIGHLY recommend something like the Lightweight Java Game Library (LWJGL) http://www.lwjgl.org/ You may not have many problems with Swing (though I think of many off the bat) but if you want to learn how to ...


1

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


0

As @user3068350 said, both Game and ApplicationAdapter implement ApplicationListener. It's useful to extend Game if you plan on using the Screen interface in your game, however some developers may wish to take a different approach and handle screen management their own way. If this is the case, these will extend ApplicationAdapter. Personally, I like my ...


0

The Game class implements the ApplicationListener interface and is just a class that is designed to make it easy to switch between different screens. When a method in the ApplicationListener is called, the Game class takes care of delegating it to the currently set screen.


0

I guess you are looking for the constructor: GestureDetector(float halfTapSquareSize, float tapCountInterval, float longPressDuration, float maxFlingDelay, GestureDetector.GestureListener listener) The default constructor has this values: halfTapSquareSize=20, tapCountInterval=0.4f, longPressDuration=1.1f, maxFlingDelay=0.15f. I don't ...


0

As @drumbumLOLcatz says, there are a bunch of overloaded methods when you create your shapes, what you are looking are for those methods that involve a degreeparameter. Something like this: public void rect(float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float degrees) So everytime ...



Top 50 recent answers are included