New answers tagged

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


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


0

What comes to my mind would be to have a list of each collision box per frame of the attack, then advance each hit box every frame and check if it collides with any enemy. If so, set the attack hit to true so the enemy doesn't get hit twice or more times for the same attack. If this doesn't make sense, here's an example of the code in Java: public void ...


0

Instead of having the nextString method in the key event method, have it in a update method. Similar to the comment, it depends on the OS, so they won't always be the same. This might have sounded confusing, here's an example: public void keyPressed(KeyEvent evt) { if(evt.getKeyCode() == KeyEvent.VK_LEFT) { player.runMotion = -1; } ...


0

Whenever you modify a camera's position, you need to call camera.update() so that it will update all of the other variables that the camera uses. This update call should be done before any drawing is done. In my games, I usually call camera.update() at the beginning of my render function. Second, it looks like you are calling camera.translate(100,100) every ...


1

It would appear your rendering logic is completely flawed. Take a look at this question and it's answers, you appear to be doing some of the same errors I previously did. Canvas - good rendering practices? About Projectiles Drawing one rectangle will literally never have any noticeable impact on your frames so there is obviously a flaw elsewhere, ...


0

I tested it. it is caused by if(delta >= 1){ tick(); updates++; delta--; } Change it to if(delta >= 0.0001){ tick(); updates++; delta--; } .If this doesn't then it is probably the problem of your computer being too slow. But don't worry, this is not a big deal.


1

This is most likely because to make more than one instance of this you will need an array of these objects. Usually there would only be one player and multiple enemies so the player would be a single object and the enemies an array. Here's do simple code to explain this: Enemy[] enemies = new Enemies[10]; for (int i = 0; i < enemies.length; i++) { ...


0

From what I've read so far, I think these jMonkeyEngine would be a great candidate for this. If you want to jump right into it, LWJGL is also an excellent choice. But for the idea itself, you will most likely have to use specific coordinates that will be looped through to be filled with the smaller cubes.


1

From my experience, it's not expensive to bind textures. I have a program that binds about 30 textures per frame and it runs pretty smooth. Since you're using only 9 textures and VBOs on top of that, I imagine your game actually runs very well.


0

Let's assume you have float gameTime; Let's also assume you spawn in the blocks completley randomly. And finally let's assume you have some kind of update method which gets called every frame. With the above assumptions you could probably write something like this float gameTime = 0; //The total game time, in seconds. float spawnTime = 0; //A counter to ...


1

A first aproach could be giving a varying weight to each type of block, modifying such weight each level, decressing the probability of spawning an easy blocks and increasing the probability to spawn a harder ones. I'm also going to suppose you have some kind of a parent Block class and different child classes for each type of block. public Block ...


2

I suppose the Tile class is the class of which all the "balls" are an object of? (i dont have much time to read the code). If i understand correctly, what you are asking is how to change the balls color? if yes, i would suggest that when you want to change a balls color just get the tiles from your Tiles array and just: board[x][y].background = //the new ...


2

Your code isn't wrong at all. You are dealing with matrices and vertices the right way (your 3D simulation actually works), and even texture mapping is fine. Matter is, your texture mapping algorithm uses just a linear interpolation to map a point in the 3D space to a point in the 2D plan of a given texture. Texture mapping When mapping texture to mesh ...


-1

They added it to build 79, the method is called: glfwSetWindowIcon(long window, Buffer images);


0

The fact that your methods are abstract is secondary, here -- the main issue is that you're calling the methods as if they were declared static: Game.init() Game.render() Instead, what you need in order to call these methods is an instance of the Game class and invoke those methods on that object: Game game = new SubclassOfGame(); game.init() ...


3

An abstract method is a method without a body. So you can't just call an abstract method of an abstract class (you cannot instantiate an abstract class directly). If you want to have your abstract game class with the abstract methods you need to have a class that extends this game class and specifically implements these methods without the abstract keyword. ...


1

Dont know how your particle system is written but it is very possible that your bottle neck is the communication time between CPU and GPU. Not going to go into too much detail but just know that this operation can be very slow because it causes stalling. Perhaps the idle time you see in profiling is due to that. What a good particle system do is to move all ...


0

From my own personal experiences, you can't really add the res folder into the jar file unless you use InputStreams (this is so that the game can read the res files inside the jar file and not in the same folder), however, you can add the native files into the jar. With JarSplice, there is a tab called "Add Natives," you use that tab to locate the natives ...


-1

The reason why your game takes up 15% CPU is because of your map size, which is 1024*768, and the game constantly has to run this map several times each second in the render() method, which of course would take up memory. I would suggest following this tutorial on TiledMap rendering (https://www.youtube.com/watch?v=0BivL6Carh4), start watching at around 6 ...


0

So I found the solution and I find it rather odd. Basicly I increase the overal alpha-value with 100*delta. Sometimes the result is >1, and appearently libGDX can't handle an alpha of 1.1, blacking out the screen (drawing at alpha 0.1 propably?)


0

If your class implements InputProcessor: @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { MoveToAction mta = new MoveToAction(); mta.setPosition(screenX, Math.abs(stage.getHeight()-screenY)); mta.setDuration(5f); //moves to new location by this time interval stage.addAction(mta); return false; ...


3

I would take a look at glDraw*Instances (Instancing) Also, reducing vertex count for a large amount of small particles is extremely important. I don't know if your using a model or a single 2D texture or what, but some general tips: Use as few verticies as possible. If using transparency in your textures, use glAlphaFunc to reduce blending needed. If ...


0

I would agree with using the TweenEngine. It's relatively simple to use and provides a lot of functionality. To tween a value you first have to create a TweenAccessor. It would look something like this for a Sprite: public class SpriteAccessor implements TweenAccessor<Sprite> { //Used to identify what type of tweening you wish to do. public ...


0

After sitting with this problem for hours I finally found out what was wrong. If you set the shader to null on your SpriteBatch, it uses the default shader provided to the SpriteBatch. For me, the default shader was Assets.getDefaultShader(), so when I set the shader to null it just used that shader. I fixed this by simply not settings a default shader to ...


1

you can do like this: In your hud class public jumpButtonPressed = false; buttonJump.addListener(new InputListener() { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { jumpButtonPressed = true; return true; } public void touchUp(InputEvent event, float x, float y, int pointer, int button) { ...


0

How do I know what the camera distance is from the image plane? I'm not sure if this is a meaningful question to ask - what is the image plane? A real camera has a plane on which an image is formed, but in OpenGL there is no such thing. If you need this for some physics-based calculation, you could possibly use the near clipping plane distance (third ...


0

Use floats for your logic & cast or round then to integers as you pass them to the drawing methods.


0

According to this section in the AssetManager page. When Android pauses, then the managed libgdx elements, like Textures, get cleaned up an have to be reloaded when the app resumes. To do this, you call Texture.setAssetManager(manager); and then call update on the asset manager like you did when you first loaded. Secondly, Android apps have no guarantee ...


0

To expand on @user3068350's answer, something like this should work; public class MyGame extends Game { private Stage stage; private Texture myTexture; private TextureRegion myTextureRegion; private TextureRegionDrawable myTexRegionDrawable; private ImageButton button; @Override public void create() { myTexture = new ...


0

If you want to get position A relative to B, you just need to substract them, like you were doing. If you want to make use of the methods, you can use the method "sub": https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Vector2.html#sub-com.badlogic.gdx.math.Vector2- Vector2 relative = A.sub(B); //contains the position of A relative ...


0

A drawable has information about its size and how to draw itself. It's used to determine size and position by ui components. Since you are using a texture, you can use a TextureRegionDrawable. Drawable drawable = new TextureRegionDrawable(new TextureRegion(playTexture); ImageButton playButton = new ImageButton(drawable);


1

I'm not going to go into details, but what you should be looking into is something like WinAMP's MilkDrop plugin presets and porting them to a shader. A good selection of example shaders (and how to write them) can be found at https://www.shadertoy.com/. These examples run on WebGL and use the GLSL language to render procedural content that is usually fast ...


4

The Android memory profilers that comes with the Android Developer Tools will allow you to figure out what is consuming your memory. It comes in three parts; Memory Monitor (this is used to find performance problems, so we can ignore this one for this particular problem). Tool Heap Viewer Allocation Tracker Using the Heap Viewer you can take snap-shots ...


1

Unfortunately - No. Unity only supports: UnityScript (JavaScript for Unity) and C#. Boo support dropped in Unity 5. But C# is very similar to Java, and I for myself started only with Java knowledge and it was no problem for me to learn C#.


0

No. As far as i know, Unity is only made to use JavaScript and C#.


0

There are a few ways to do this. This is the solution described by poirot: I ultimately achieved what I wanted using the stencil buffer combined with my own shader... The texture drawn to the stencil buffer was an elongated rectangle with rounded corners. The texture drawn to the image buffer was just a stretched red rectangle, which as you can ...


2

It looks like the edges get a fractional alpha based on the edge coverage. Problem arises when two edges fill 100% together but are blended as translucency, not coverage, only applying ~75% color. It's like the difference between covering your eyes with both hands vs covering your eyes with two pair of sunglasses. I only know how this works in opengl, but ...


0

The InputProcessor interface has touchDown() and touchUp() methods. Create a class that implements the InputProcessor interface and then give it to libgdx via MyInputProcessor inputProcessor = new MyInputProcessor(); Gdx.input.setInputProcessor(inputProcessor); I thought I should also note that if you are using scene2d and you want to react only when a ...


1

If you want to use sqlite with libGdx you can use opensource project gdx-sqlite . gdx-sqlite is a cross-platform Libgdx extension for SQLite database handling. The extension abstracts database handling to provide a unified method to handle database transacitons across multiple platforms while also adding SQLite support for desktop version of Libgdx ...


1

I've stumbled on an answer for creating a decent and easy GUI system from playing around with my game. Currently it draws the images of items onto the GUI screen, but more can be done in the future. This is essentially how I have it setup: Over-World State: EntityPlayer {picks up} --> Item (i.e. ItemPotion) --> {goes to} Player Inventory The Player walks ...



Top 50 recent answers are included