New answers tagged

0

In your case, you do have some experience on certain areas and have done a good research. However what every expert recommends is to begin simple. Grab a simple and minimalist game and try to recreate it by your own means. This way you'll be practicing and you'll be learning in the process. Later on you can start creating new ideas and transforming them on ...


4

Mathematically speaking, a distance is a value which is never lower than 0. You can see this thing in your getDistance() function implementation: the argument passed to the square root function is a sum between powers of 2. A power of 2 is always positive, their sum is positive as well, and the sqrt() function will always give back a positive value. So, no ...


0

You probably didn't import the classes Player and Connect4Ui. They seem to be in other packages, so you should write something like: import userInterface.Connect4Ui; at the beginning of your ConnectFour-File


2

Your best bet is to make a class that replicates Javas Graphics class in LWJGL. For textures you can write your own LWJGL wrapper or use Slick 2D


-3

A grid. Implementation is more simple and often times superior in performance. Edit: Hu, why the downvotes? This was more of a follow up info to the accepted answer. The OP asked for alternatives. You can find grid vs. quadtree discussions everywhere. Bottom line is a quadtree doesn't deliver a better performance (often times it's slower) than a simple grid ...


0

The problem is that your update function is only fixing the position of the balloons to the Box2D body. Since the Box2D body is created and added to the world on creation, the body will still be moving even though it is not drawn. You can disable the balloon's bodies until they are ready to be drawn, like so: Balloons.java public void defineCollector(...


0

No, you don't have to keep seperate assetmanager for different game states . One Assetmanager is enough for all the states. Moreover adding multiple Assetmanager leads to increase the load of GPU. Which will effect your Game play. So better use only one Assetmanager to load the all Assets. And Assetmanager is one of the class which should be disposed ...


1

in your update method you should add the below code. if (Gdx.input.isKeyPressed(Keys.BACK)) { game.setScreen(new MenuScreen(game)); } // and in your game Screen classes show method Add this code Gdx.input.setCatchBackKey(true);


0

texture = new Texture( Gdx.files.internal("Menubckgrnd/MenuScreen.png")); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); // here 2048 and 1238 is the actul width and height of the image . so replace these values with your images height and width TextureRegion region = new TextureRegion(texture, 0, 0, 2048, 1238); ...


1

It is a little bit difficult understanding your question, but I think your problem is caused by the fact that you update all ballons in the update (float dt) method even though you're not drawing them. This means that when 200 iterations has passed and you draw ballons and ballons2 for the first time, they have already moved some distance.


0

Each time you put your fingers on the screen the originalDistance / currentDistance will result in the value 1. If you use this value directly the zoom would always start at zoom = 1.0f. To solve this issue you should store the current zoom factor at the start of the zoom and multiply this with the new calculated ratio. So: on touchDown take the current ...


1

The algorithm you are using right now has a runtime of O( n^2 ). A tree structures can help you get that runtime lowered. Quadtrees have O( log(n) ) From that you can calculate if you will benefit from a quadtree.


2

More code would be helpful, but you likely need to put this in your show method. public void show() { Gdx.input.setInputProcessor(yourInputProcessor); // This should keep it from exiting. Gdx.input.setCatchBackKey(true); ... }


0

Turns out the answer has to do with alpha channels and the way they were being processed. I removed transparent pixels from the edges and it works as intended now.


0

This may be the same problem as this question on SO (haven't used TextureAtlas before so not entirely sure)


0

I don't know if the method you posted is called every frame, but (Hud.getTime()==0&& Hud.getScore()<(level*15)+50) will always be true once the time is up. (thus giving that linear impulse and starting the sound every frame). I would try to nullate the score.


1

Your primary question is: So how do I implement the force? Considering that your body is always underwater, there's an easy way out of this one: just use gravity :) As iforce2d points out in his tutorial on custom gravity, you can set the gravity scale of any object: //Box2D v2.2.1 onwards body->SetGravityScale(0);//cancel gravity (use -1 to ...


0

Converting mouse coordinates into tiles coordinates is quite simple, as long as you know the width and height of your tiles. All you need to do is, converting mouse coordinates into world coordinates, then performing simple math to get the indexes of the tile the cursor in lying on. Let's have an example. A small grid We have an 8x8 grid consisting of ...


0

Libgdx provides Texture and TextureRegion classes that should do what you need. A Texture is a handle to the entire image. One way to load it is Texture dogTexture = new Texture(Gdx.files.internal("path/to/dog.png")); and a Texture is drawn using a Batch //x,y,width and height are where and how big the texture is drawn in your world batch.draw(...


0

Swing / Java2D doesn't have a concept of a camera, but what you can do is store the transform of the camera, and apply that first before any other transforms. Also note that you are almost certainly going to run into unpleasant performance problems if you're not using an OpenGL-based rendering system. (I speak from years of painful experience.) I would ...


1

The problem is in your game loop You are limiting your rendering fps to your game world fps. You should update your world on a fixed timestep and either leave the render timestep to vsync or limit to something like 60.. You're using non floating point variable types where you should be using floating point math. This adds imprecision and can cause ...


0

You could just try leaving VAO calls out of your code and bind VBOs etc. where VAOs are bound in the tutorials.


0

The issue is probably because of Texture Filters. And it's not LibGdx problem either, but OpenGL's. You can set filters for Libgdx textures using setFilter() method. For eg., try setting the filter to: yourTexture.setFilter(TextureFilter.MipMapLinearNearest,TextureFilter.Nearest); Here's the detailed explanation written by Mario himself.


0

Do you have called that in your render method: Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Because, it looks like your code should work. We figured out, that he needed to disable, because he wanted to draw the Screen on demand "continuus rendering" https://github.com/libgdx/libgdx/wiki/Continuous-%26-non-continuous-rendering


0

I think that the most simple way of getting around your problem is as follows. I assume that your player entity helps you keep track of his state. Maybe it's running, or climbing or whatever you might have used. If you add to make sure that the only time you will ever check if the player sprite is on top of an enemy is when the player's state is falling, ...


1

Brief: The solution is not in collision listeners, but in collision filters. Collision filters have a shouldCollide method that you can implement to return false if you want to disable collision or true to allow it. Collision filters are executed before collision listeners. You can use, for example the linear velocity of the player sprite to decide if you ...


0

Creating only one is probably better. If you have one object storing and managing the lifetime of assets that you share between all levels, that makes it trivial to share assets across each level (for example, common, always-loaded assets). If you have one asset storage object per level, that does not naturally lend itself to sharing common assets (you ...


0

I would do what the above posters suggested, Shadow and size increase when ball is higher. A thing I remember from playing tennis on old TV games is that the ball also slowed down the higher it went and bigger it became. When it reached it's zenith and started "coming down" it would start going faster again as it became smaller.


0

I fixed it by changing the main update loop and i followed this ordrer Input Physics (World & Bodies) Camera (position & update) Graphics Box2D Renderer (if neeeded)


73

Shadow and texture. Texturize the ball to show it rotating. This helps give the illusion of rotation of a sphere, which is more than 2 dimensions. A shadow can trick your brain into believing all sorts of things. Making flat things look like they have a third dimension. You don't even have to change the height of the ball, you just need to change ...


1

Shadow and Ball are key aspects. Shadow size and distence between Ball and shadow should increase when height increase. Also, Ball size should increase when Ball height increase. Shadow position represents position of ball in 2d and when Ball height increase you have to change Ball position (I m assuming that light source is homogen and it is not single ...


74

Give the ball a height value. Draw a shadow at the ball's actual 2D position; the shadow will help spatially orient the ball for the player. When you draw the ball itself, offset the Y position by the "height" of the ball. If you want to implement more than just an illusion, use this height value in computations as well -- for example, you can implement the ...


-1

You draw a shadow below the ball, like it's done in the gif. The higher the ball, the longer the distance between the ball and the shadow.


0

You don't need to do batching in Java(but if you want to try it here is a link to a usefull link: https://www.youtube.com/watch?v=X6KjDwA7mZg), let me tel you why: The idea of batching is to draw all models that have the same texture and other data, like vertex data, in batches so that you minimize the amount of binds and unbinds for said data as much as ...


0

Here's the documentation on the type Vector2 in libGDX. https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Vector2.html From this I can guess that code you could use would be something like this: //Setup the positions of the player and the target position Vector2 targetPos = new Vector2(Gdx.input.getX(), Gdx.input.getY()); Vector2 ...


0

I found the answer: My game is actually very small but I resize it by a scale factor of 4. So I also have to divide the width and height of my bufferedimage by 4 inside the light render method public void render(Graphics2D g) { BufferedImage image = new BufferedImage(GamePanel.width / SCALE, GamePanel.height / SCALE, BufferedImage.TYPE_INT_ARGB);


1

You need to learn a little bit more about vectors but I'm going to explain it anyways. First of all, let's say that your 'game unit' is in pixels and that points (coordinates) and vectors have two components x and y. Let's assume that you have two given points A = (x1, y1) and B = (x2, y2). To get the vector between A and B, you have to do the following ...


0

To get from point A to point B where both A and B are vectors, the direction is the vector normalize(B - A), lets call it C. The velocity you're looking for is the direction-vector C times the speed in units per second. So if A is your actual position, B is your target position, 10 is the speed in units per second and delta is your deltatime, then your ...


0

Lets start of by defining a few variables. Lets say that o is the position of the player, d is the point that we want the player to look at, c is the position of the camera and dist is how much do we want to move c towards d, were dist is a float between 0 and 1. float cX = (dX - oX) * dist + oX; float cY = (dY - oY) * dist + oY; In case you want to move ...


0

The method I would choose for this is to just use your existing map for as much as possible. This is essentially your first approach. Yes, you will need to figure out the IDs of trees (and other relevant objects), but on the plus side you don't need to make any changes to how you're creating maps, storing them, loading them, rendering them... Regarding ...


0

The representation of game state should be the core of your architecture, because it ties everything else together. Player actions, the sequence of events in a turn, card effects are strictly layered on top of game state. For example, you can have an index of triggered abilities by the type of event that triggers them, and when anything happens you could ...


1

Threads would definitely be overkill here. I would use event listeners. First, make an ICommand interface. (The param is so that you can optionally pass data to your command) public interface ICommand{ public void execute(Object param); } Then make sure you clearly define every scenario in which a card will activate and create a ICommand variable in ...


1

Solved After thinking this through almost a complete day (I encountered the problem yesterday), I realized I had the function to determine the height of any given point using the distance to the ocean. Why would I need to take averages and complicated calculations if I could just check the distance to the nearest coast, and then use the formula?


0

I encountered a similar problem while working on a project of mine. The player was able to pick up a certain variety of weapons, which shoot different type of bullets. I'll help you to figure out a solution for you by explaining the solution I found for my game. In order to take advantage of inheritance and polymorphism, I managed to work out all the ...


1

An Alternative Approach As very astutely stated by Dan in the comments to your question, trigonometric functions are very expensive to calculate and for something as simple as a bouncy ball you can keep to simple and fast vector math. It appears that you're only doing AABB collision so this method will work perfectly for you. What to change Your Ball ...


2

Expanding on Greffin28's Answer Tile Based Collision Detection in Games In tile based games it's really easy and fast to detect whether an object is colliding with a tile. Some psuedo- code to accomplish this: /** * Moves our entity along the x, then y. If we do both at the same time the entity * will not move if any of the collision detections fail (won'...


2

For accessing the array i suggest you make a function like the following: String getState(int x, int y) { if (x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT) return "g"; // Let's say all blocks outside the map is solid. return blocks[y][x].state; } This simple function can save you from array out of bounds error. Basically, the function ...



Top 50 recent answers are included