Tag Info

New answers tagged

0

In either cases you'll run out of memory. For lines you need to discard old lines, or simplify the lines as you go, or both. For pixmaps you'll need to make multiple pixmaps in a grid and either discard them when they go off the screen or write them to the filesystem and reload them when you come back. And eventually running out of disk space if your world ...


0

It's been a bit since I used LibGDX, but doesn't the setToOrtho function have a bool that defines whether the camera is flipped or not? It looks like your whole screenshot is flipped, so instead of camera.setToOrtho(false, width, height); try using camera.setToOrtho(true, width, height);. If it is just your player who is flipped (which I'm guessing is a ...


2

Try running the java VM with the option -Xss8M to set it to 8 Megabytes. You only have 9 Threads so you should be fine with 9x 8M stacks. Then reduce the amount until it crashes again, bring it back up a bit, then document in your FAQ that this option is needed for some video drivers. java -Xss8M -jar myjarfile.jar The crash logs points to the Intel ...


0

I guess you're switching to "normal" state too early. In fact, you're doing it right after you switch to "jumping" state, with just one instruction inbetween, so actually its like continuos "normal" state, "jumping" is to short to ever get noticed by render method. Jumps should last some time, and then you should switch back to "normal" state after you land ...


0

It is never called because in the touchDown function you are calling stateModifier("normal") right after stateModifier("jumping"), so the state will be set to NORMAL when the function ends. In the update function you are testing if the state is equal to JUMPING, but is not, it will be NORMAL.


1

You could update the position over time: currentPos = currentPos + Math.signum(currentPos - touchedPos) * wayPerTime * deltaTime; wayPerTimestep is your velocity. deltaTime is the time passed since the last update. currentPos is the current position of your player (might be x, y or both as vector). touchedPos is the position the player has clicked on the ...


1

You can use InputAdapter class and methods touchDown(int screenX, int screenY, int pointer, int button) Called when the screen was touched or a mouse button was pressed. boolean touchDragged(int screenX, int screenY, int pointer) Called when a finger or the mouse was dragged. boolean touchUp(int screenX, int screenY, int pointer, int button) Called when a ...


0

Don't know about touch listener, but I can help you with polling based input. Here's how I'd handle input for the sprites // assuming you have the input touch co-ordinates if((touchX>= sprite.getPosition.x) && (touchX<= sprite.getPosition.x+sprite.getWidth()) && (touchY>= sprite.getPosition.y) && (touchY<= ...


0

Adjust birdSpeed and pixelMovement in below code to achieve your 9.8m/s2 speed. s=0*t+1/2gt*t Public Class bird extends Actor { private float pixelMovement=30; // No of pixel you want to move bird in one touch private float birdNextPosition; //This will be used to hold next position of bird private boolean birdisMoving=false; // flag to track bird ...


0

On your run configuration make sure you have set your "Working directory" to your asset folder. Example: This only applies for the desktop run config.


0

try it like this, mPhysicsWorld.setContactListener(new ContactListener() { @Override public void beginContact(Contact contact) { final Body ballA = (Ball) pContact.getFixtureA().getBody(); final Body ballB = (Ball) pContact.getFixtureB().getBody(); Body bodyFound;//find body of interest from ballA.getUserData(); and ballB.getUserData(); ...


0

You shouldn't create new InputListener, but you need to use one that you register in Gdx.input.setInputProcessor this.addListener(stage) Didn't test.


1

In this line ball.applyLinearImpulse(new Vector2(0f, 5000f), ball.getPosition(), true); I think the point where you put force it relative to object position, so you put impule in ball.getPosition() + ball.getPosition() Try to use public void applyForceToCenter(Vector2 force, boolean wake) or ball.applyLinearImpulse(new Vector2(0f, 5000f), new ...


1

How the author specifically got that value was via experimentation. From the comments: Q: Hi James, you set acceleration.y to 460. How did you find this number? Is it static? A: Acceleration was experimentally determined. Its value does not change. And this is often the case when determining values for your game. You pick a value and play-test ...


1

I suggest moving the target slowly rather than the angle. Try this: Vector2 Target; // Interp is a value between 0 and 1. When 0, the target never moves. // When 1, the target moves instantaneously. Intermediate values cause the target // to move at different rates. void UpdateTarget(float interp) { Target = interp * Mouse.Position + (1 - interp) * ...


1

I think any linear function would be fine for this. You can keep two variables one for your spaceship's current angle spaceshipAngle = Math.PI*k, and one for the current angle that the user inputs with his cursor cursorAngle = Math.PI*p. And what you do is if (Math.Abs(Math.PI*k, Math.PI*p) < Math.PI) { if (Math.PI*k < Math.PI*p) k += ...


0

There is no 'special rendering method' to call on Android with libgdx. In such situation, you should first look at what you are doing differently on each platform. So, according to your code, there is indeed some difference between Desktop and Android. On Desktop you have already implemented controls for your character in the checkKeys method of the Player ...


0

This could be due to double & triple buffering and processing spikes, probably due to GC. frame 0, delta 0, display buffer 0, draw buffer 1 time passed: 0.016 frame 1, delta 0.016, display buffer 1, draw buffer 0 (at +0.016) time passed: 0.016 frame 2, delta 0.016, display buffer 0, draw buffer 1 (at +0.016) time passed: 0.032 hickup frame 3, delta ...


0

The libgdx camera type OrthographicCamera has an unproject method. Supplying this method with the screen coordinates of the mouse click will give you a position in world space you can then use collision detection with on your tiles. The following code shows how you might get the mouse coodinate and traslate it into a world space point. Vector3 clickPos = ...


0

camera = new OrthographicCamera(); camera.setToOrtho(false,800,400); Above code will draw everything in your game on 800*400 virtual screen (in pixel) and fit, stretch, fill etc (see viewports ) on device's screen, independent of device screen size. https://github.com/libgdx/libgdx/wiki/Orthographic-camera https://github.com/libgdx/libgdx/wiki/Viewports


0

You dont need to specify android screen fix size if you want you Libgdx project on all android Devices. I have test this. Just specify screen size that you can get from Gdx.graphics.getWidth() and also for Height. You can give some fix value to Camera.. Test it on different android devices and this will work same on all.


1

The conversion from a unit to another is a matter of a simple multiplication. You can implement a ConvertUnits static class with functions like ConvertToGameUnits(), and ConvertToBox2DUnits() to make it easier. I haven't used libgdx or Box2D, but i have used Farseer Physics engine which is basically identical with box2D but made for C#. With that being ...


1

What makes you think this is the shader code that is slow ? In most machines nowadays, and especially mobile devices, the bottlenecks are not these purely calculation-fed (ALU loaded) shaders, but memory bandwidth. Memory bandwidth is used by framebuffers being fed to shaders as textures, or by the ROPs writing to the render target. Especially bad when ...


0

SOLVED, i had to pass the enemyRunTime to batcher when drawing each enemy, instead of the global runTime.. like this: private void drawEnemies(float runTime) { enemyArrayLen = catta.activeEnemies.size; for (int i = enemyArrayLen; --i >= 0;) { currentEnemyAnimation = catta.activeEnemies.get(i).getCurrentAnimation(); ...


5

Sarting with the clouds, a simple method is to draw them as three layers: Layer 1 is the bottom layer, and is drawn first. It just contains the cyan background. Layer 2 is the middle layer, drawn between the other two, and it represents the 3D highlights. The background in this layer would again be transparent (represented by a purple colour in the ...


3

You could achieve this effect using parallax scrolling by making the earth and each shade of green a separate layer. With a parallax effect, no 3D calculations are required, and you get to stay with the pixelated, simple color style you're using. Note that parallax doesn't have to be limited to just horizontal motion. Vertical movement (when the camera ...


0

You can add a depth component to your 2D textures and set the depth value in the pixel shader. There will be some performance loss due to setting the depth in the pixel shader but shouldn't matter for a 2D game on PC. The other way is to use multiple layers of 2D textures for your background.


1

Check out the principles behind stencil buffers and/or masking. Essentially what you want to do is generate a mask/stencil to mark out your drawing area and use this mask to decide if the user can draw or not. For example, take your shapes you want the user to draw on and render them as pure white into a full-screen buffer, with a default colour of black. ...


0

The setBounds() method comes from the Actor class, which the Table class subclasses. It is usually used for stuff like collision detection, but not setting the size of your actors. In your case, you can go as simple as calling table.setFillParent(true); to have your table fill up the entire space in its parent (btw, are you adding it to a stage or ...


0

To prevent echoing, avoid overlapping all the sounds : Check if bullet sound has finished playing Stop the current sound and play the next/reset if (bulleSoound.isPlaying()) { bulletSound.reset(); } else { bulletSound.play(); } As GuneyOzsan says, you certainly can randomize by adding more bullet sounds


2

This problem is usually a sound design problem, not a coding problem. These problems occur mostly because of insufficient use of random variations in sound samples. You should first make sure you are using a pool of different recordings of the same sound and play a random one each time you fire a bullet, or make small random variations of the pitch on the ...


2

That spacing is called font kerning. And that is exactly why there is padding in front. The purpose of kerning is so that letters fit nicely next to each other, and that they aren't too close or too far away from each other.


0

If someone is able to pick through the binary and find out the algorithm - you'll never really be able to prevent that, so don't bother. To stop simply use a cryptographic hash! Suppose you have this: function computeHash(levels) { code = ""; for(level in levels) { code = hash(code+level+level.isComplete()+"MAGICSALT") } } It's ...


9

You can create a replay file as proof of work while the player is playing. Start the game, save the starting conditions including the name of the level and the pseudorandom seed, record the exact timestamped input states (mouse movements, key or button presses, etc.) that your game's input layer passes to its logic layer, and stop recording once the ...


0

You have the freedom to create your own button class, attach to it a sprite, make some methods to handle input and your good to go. public class SimpleButton { private Sprite skin; public SimpleButton(Texture texture, float x, float y, float width, float height) { skin = new Sprite(texture); // your image skin.setPosition(x, y); ...


3

If you want to do this totally in the client side and you don't consider the private storage provided by your platform to be secure enough (e.g. if there's actual money involved in completing levels), what you need is a proof of work. Your save file must contain an information that is designed such that creating the information is difficult to calculate ...


1

If you prefer using an external file to hold save information and it is in a place that would be tamper-able by users you may want to read up on how encryption works and use that to prevent anyone from being able to make meaningful changes to the file. Something like a Feistel Cipher should be a good starting point and would be sufficient to stop someone ...


18

Storing the completion information in a local file is a simple and perfectly acceptable method of doing so. Fundamentally, this is what every game will do to track progress (in some fashion, although the specific formats used for the data and the storage mechanism will differ). Protecting the file from tampering is more difficult. If there's no compelling ...


2

I use Interpolation.bounceIn.apply(current_position, target_position, smoothness) to achieve this effect. Take a look at this. Edit I found the answer on their site MoveToAction action = Actions.action(MoveToAction.class); action.setPosition(x, y); action.setDuration(duration); action.setInterpolation(Interpolation.bounceOut); actor.addAction(action); (I ...


1

Gdx.gl.glClear : as .glClear suggests, this function clears the screen before drawing the next frame. It depends where do you instantiate your font object (as you're using libgdx I guess you use BitmapFont to create your font object). An approach could be to instantiate it in the main class (the one that extends Game), and whenever you want to draw it on ...


0

Okay, So I think you're asking how to do it so here's my Bullet class remodeled to fit a player. Keep in mind this was a bullet class so edit it to fit for your player. Pay close attention to the use of Vectors. public class MovingPlayer { static final float PLAYER_SPEED = 800; Vector3 position, velocity, acceleration; Texture texture; public ...


1

You should not do it like that. Use scene2d for your buttons and menus and use InputMultiplexer to set up multiple input processor.


0

buttonDown() and other methods inControllerListener only fired when the key is pressed.If you want constant movement you need a variable and set for example when KeyRight is called and unset when keyRight is released or another key like KeyLeft pressed There is a good sample here ...


0

You will need to normalize the rotation matrix to remove its scale. This can be done by normalizing all 3 rows of the transform basis matrix. new btMatrix3x3( transform.getBasis().getRow(0).normalize() , transform.getBasis().getRow(1).normalize() , transform.getBasis().getRow(2).normalize() ); or new btMatrix3x3( transform.getBasis()[0].normalize() ...


2

This issue happens with some MSAA or CSAA implementations. Try disabling anti-aliasing and see if it goes away. If that is the case you might need to force multi-sampling resolve before rendering your transparency. The other solution would be to force some overlap of your tiles.


0

I think you want method 1, not method 2. I assume you a constant turn rate towards the desired heading? In that case, torque, being angular force, is not what you'd want to use here. (You'd need infinite torque to get the initial immediate start, and then infinite torque to stop immediately at the target direction) so the first method is more accurate. ...


0

I'm still rookie about libgdx and I currently started to port my android game to iOS via libgdx. In the android version I have drawable folders (assets) for different screen densities and resolutions and the loading of the proper ones works automatically (android knows which folder to access based on the device specs). What I read everywhere for libgdx is ...


1

To get rid of the lines, you need to set Pixmap.setBlending(Blending.NONE); before you draw the circle.


0

Okay, I found an answer. You need to set the camera's position directly after calling world.step() and then it works without shifting. world.step(...); camera.position.set(...); camera.update(); (Original Answer)


5

Here's a vector-based solution. I haven't tried it, but it seems fine conceptually. Theory I gather you've stored the shape as line segments. Here's the letter A represented with three line segments. I've assumed that paths in the user's drawing are stored as lists of points. We can "inflate" those line segments to allow an error margin when checking ...



Top 50 recent answers are included