Tag Info

New answers tagged

0

This needs to be done when you create the Box2DLight's Light object. You can fix this by setting the setSoftnessLength(float) on the Light object. For example: m_Light = new ConeLight(...); m_Light.setSoftnessLength(1.5f);


2

C++ should be very efficient, but it also would make me have to worry about low-level details like manual memory management, and compiling for different platforms. Modern C++ highly discourages manual memory management. You should instead use smart pointers like unique_ptr and allocation functions like make_unique and never manually allocate or ...


1

About c++: You dont really need to worry about memory management. Ofc you handle memory yourself, but its not as hard as in C. In C++ you just allocate your memory by creating a Object (new xyz();) and free this memory by deleting it (delete var;). No more manual malloc() and stuff) About Java: Java supports Call-by-value with primitives and ...


0

An animation is just a group of frames which are drawn sequentially. If you were able to render one animation, to change it you just have to change the frames. That example splits a Texture into TextureRegions by splitting it in a grid, I recomment you create a TextureAtlas instead, its easier to access the different TextureRegions in it. To change the ...


0

Looking at the slick-util documentation, it doesn't look like there's a way to just change the x, y, and z positions while a sound is playing. The following is a work-around I could think of off the top of my head, but I don't know how efficient this would be So, every time the camera position changes (or maybe only when the camera position has changed ...


2

Sure, why wouldn't it? As stated on BadLogicGaming's Official Website: The license basically states you can do with the source whatever you want, copy it, modify it, include it in open and closed source projects without getting infected by the license itself. You can do whatever you want with what you made. Just make sure you comply to these 3 lines if ...


0

Let me get this straight: render performance is in (almost) no way related to the programming language, but to the graphics API used (Ex: OpenGL, DirectX, software, etc.) The programming language used is only an interface to these APIs and will not affect graphics performance. What the language will have an impact on is the arithmetics. If you want to do a ...


1

Java is a bit slower then c++ however this effect is less then people tend to think. There are several points on which it matters: 1 Calls towards openGL will have to take another extra step this means that if you make many calls towards openGL you pay a small penalty (not that large but it's there). 2 You don't control the garbage collector that means ...


1

As per Andy's comment: Nevermind, I fixed it. I just had to take out the p.setCenterX(center.x);p.setCenterY(center.y); out of the render function.


1

Ah! I missed the obvious reason for the odd behavior while first looking at your code (I think). Essentially, there are three potential problems here: First: Missing Updates Each and every iteration you'll update your game logic only once (or not at all). In a similar way, you draw your screen (or skip drawing). However, this causes one problem: Let's ...


0

This is a well-known feature of libGDX: the Y-axis has 0 at the bottom of the screen, not the top. (This is to be more consistent with 3D coordinate systems, which do likewise.) There are a couple of ways to "fix" this. Use a camera. You can transform the view. In your render method, calculate the Y position as screen.height - y - sprite.height. This is ...


0

As you did not show your code it's hard to answer. This is my answer. When pressing the mouse I move my 'kicker' into position and stun it's velocity. When the mouse is released I apply the mouse direction as an impulse. void mouseDragged() { kicker.setPosition(physics.screenToWorld(new Vec2(mouseX, mouseY))); kicker.setLinearVelocity(new Vec2(0,0)); } ...


0

(Most) Android devices' input are from the touch screen. If that is your case, and you are trying to fetch touch events, you have two options: 1 - Poll every frame if the LEFT key is pressed. Basicly, instead of your Gdx.input.isKeyPressed(Input.Keys.LEFT) what you want to check is: Gdx.input.isButtonPressed(Input.Buttons.LEFT) From javadoc: ...


0

Problem 1: It's possible you need to subtract your offsets from your coordinates rather than add them. This would explain why collision doesn't work when scrolling. The correct operation (addition or subtraction) depends on how your offset is defined and used elsewhere. If your player position is in world coordinates and the offset represents the ...


0

Seeing as you want to keep the state of the matrix before the translation, I'd suggest using a matrixstack, this openGL tutorial explains it quite well: http://www.arcsynthesis.org/gltut/Positioning/Tut06%20Fun%20with%20Matrices.html However, for this method I assume you perform your matrix multiplication with the vertices in GLSL. If that's not the case ...


0

You're not even using the y coordinate when you're storing your tiles. You're just using x and some random value: `( Sprite.dirtTile,x,RandomHeight)'. Which likely means you'll have tiles stacked on top of each other, meaning your list is going to contain some tiles that are occupying the same position. However, the naive approach to finding the tile at a ...


1

I'm assuming that you may be doing setTransform() on PBox to move the player around based on mouse positions. If that's the case, it is bound to happen, since setTransform occurs outside of the physics calculations. Consider adding a Joint to drag the pBox around (with large force).


0

Is something like this what you're asking for? Block blocks[][]; void removeBlock(int x, int y) { while (y < blocks[x].length - 1) blocks[x][y] = blocks[x][y+1]; if (y < blocks[x].length) blocks[x][y] = generateNewBlock(); } If you're asking about the animations for moving the blocks down, then you probably will want to keep both a ...


0

I'm now using openGL ES. I found it to be the most simple solution to my problem, since I don't need anything too advanced.


1

A simpler way, that will also speed up your program, is to check if your circle is moving towardas the other circle before check for a possible collision. You can do in it in this way: vector2 p; p.x = other.position.x - your.position.x; p.y = other.position.y - your.position.y; if(p.x*yourSpeed.x + p.y*yourSpeed.y > 0 { //check for collision; } look ...


2

Your problem is that you are checking for a collision and then stopping, this means that if your frame places you to far into an object you are now stuck. To solve this you have to solve the equation of exactly where both object were when they hit one another. So you have to find where the following is true: |t*v1+p1-t*v2+p2)|=|r| where t is time v is ...


2

I think the simplest approach is to rescale the values. The values other than the one you're setting currently sum to 1.0 - rate[index]. You want them to sum to 1.0 - r. You can therefore scale each of them by (1.0 - new_value) / (1.0 - old_value) to preserve the sum. public void setRate (int index, double r) { for (int i = 0; i < 3; i++) { ...


0

One way to do this is to add to the indexes' value by its self multiplied by diff. rate[i] = rate[i] + rate[i]*diff where i is the other to values other than index double d = 1 - rate[index] double diff = rate[index] - r; rate[index] = r; index = (index + 1) % 3; // increment and wrap around index rate[index] += ...


0

I would simply try: g.drawAnimation(player, 720, 450); I use a lot of animation and this has always worked for me. As a suggestion on the side I would consider using SpriteSheets instead of Image[]s, as they are easier to work with. Hope this helps :) //EDIT I would also check to see if init() is being called because the null pointer exception you are ...


1

You could divide diff by two and then subtract it or add it accordingly to the other two. double diff = r - rate[index]; double change = diff/2 * -1; //we need to reverse the operation for(int i = 0 ; i < 3; i++) { if(index != i) rate[i] += change; } Still you should be careful for number precision errors. For that you could use an int[] where all ...


2

Obtaining multiple key presses can be found in this answer: How do I handle multiple key presses in Java? Assign each one to a boolean variable and then check each key and add to the movement vector. Opposite keys will cancel out, and you can also test whether a key is already in use based on that. if(noDiagonal) { velX = 0; velY = 0; ...


1

Simply use shapes and AABB collisions. Keep a tiled map. Create an approximation of a circle using tiles and create a rectangle for each of the unwalkable tiles. Next, when you create a player or any movable entity, simply create a Rectangle around them too. Before moving, look whether or not the player's rectangle would collide with any of the wall's ...


1

I'm assuming you're either using some sort of entity-component system, or else you have in-game classes that represent your objects. Either way, you have some reference to your in-game objects (players, walls, enemies, etc.) At a minimum, these objects should have: A position A sprite (display) A collision primitive (axis-aligned bounding box?) All you ...


0

You can use a raycasting (or linecasting) based collision detection system. At a very high level, you cast rays from your player (preferably from the edges of it's collider box) into the game map. When the ray hits something, you can check to see what its hit, and if it's a collidable surface, resolve the collision and adjust player movement as appropriate. ...


4

Short answer: no. Long answer: Game Maker's performance are really bad. If you are a good programmer, you will find yourself hitting the performance wall more than once or pay for the YYC (Yoyo COmpiler) which unlocks decent performances at a price. Libraries like libGDX, slick2D, LWJGL or any other will beat GameMaker by a lot. Object oriented patterns in ...


1

As I understood your question, you want to get the coordinates of the points of your body relative to the world, in other words, following the transformations applied to the body. I did this function not long ago, I hope this will help you and guide you towards an answer: public Vec2[] getPoints() { Vec2[] v = new Vec2[shape.getVertexCount()]; for ...


4

If you use an algorithm like Bresenham, where the two lines can be different, depending on their start- and end-position, you then have to either: Plot both lines and use the result of both plots for your LoS calculation. Plot only one line (for example always from Player to Enemy) and use this one LoS calculation for both entities.


3

This is less a problem with Box2dLights, and more a problem with setting up Box2d collision fixtures to match your sprites. The Box2dLight rays are colliding with the CircleShape fixture you attached to the box2d body. CircleShape chain = new CircleShape(); chain.setRadius(10); Instead, this should be a Polygon shape with the same dimensions as your box, ...


1

The cross product of two vectors is a vector orthogonal to them both. If you have two vectors contained in a plane, the cross product of them gives you the vector that is normal to that plane. Knowing that, you can construct your desired coordinate system by exploiting that property. Let's start finding two vectors defining your plane. For example, PQ ...


1

By no means you need to recreate the buffers every time. Why don't you create all your buttons once and then draw them as needed? Buttons are immutable things. Suppose you had a class Button, that incorporates all the stuff needed to draw a button, such as textures and the vertex buffer: class Button { Texture texture; VertexBuffer buttonVerts; ...


1

Having one large tilemap is certainly the simplest way to go, but as you stated, it would be more efficient to have one for each zone and have the entire map cut down to a couples of square regions. It would allow you to free resources when a region is leaving the screen and reduce the range of the loops needed to draw all the tiles (though this can be ...


0

What I would likely do is convert the rectangle to a Pixmap, then, assuming the rectangle has a solid single color border (with a different color than the rest of the rectangle), I would simply iterate through the pixels in the Pixmap looking for the border color and save all the positions to an array. Then all you would have to do is periodically set the ...


2

Take a look at this. It's common to have a single image for all your tiles and draw a different part of it at rendering. You can then draw your tiles like this : int mx = tileId % numberOfTileCols; int my = tileId / numberOfTileRows; graphics.drawImage(image, x, y, x + tileWidth, y + tileHeight, mx * tileWidth, my * tileHeight, mx * ...


1

Why not using Actions.forever(Action repeatedAction) ? Example : fadeLoop = Actions.forever(Actions.sequence(Actions.fadeOut(time), Actions.fadeIn(time))); this.addAction(fadeloop)


3

For your first question you can optimize your method by only checking collisions with the border bubbles (only the bubbles that are actually exposed and not ones that are entirely surrounded). However, you can optimize this even further by using the fact that you know the coordinates of the bubble to find out approximately (or precisely, with some math) ...


2

pretty new to libgdx but i dont think it would be too hard to implement your own version of a "master volume" just have a float variable called master volume and then use it when ever you play your music and edit it how you please for example public static float mastervol = 1f; //playing your sounds sound1.play(mastervol); sound2.play(mastervol); ...


2

The problems i have run into is i can't move the WorldEvent,WorldListener, or World classes into a separate package under the moniker World.my.game because of the static reference. Don't make the listener inside the World object static. A static class member means the object is shared across all instances of the type (all instances of World in this ...


1

I'd like to help but your code is working fine for me. public static void main(String[] args) throws Exception { DisplayMode displayMode = new DisplayMode(640, 480); Display.setDisplayMode(displayMode); Display.setTitle("Input test"); Display.create(); System.out.println("OpenGL version: " + GL11.glGetString(GL11.GL_VERSION)); ...


0

My question is how to get current time that is not taken from android settings to prevent cheating? I want to prevent the player from cheating by changing android time from settings. I see only one workaround, get a timestamp from the internet. Here for example : http://currentmillis.com/api/millis-since-unix-epoch.php Of course that would force your ...


1

Size and fit can be taken care of the heuristic that declares whether a move is valid during the path finding. Once the path itself is generated it's then up to a localized movement function to handle not bumping into things on the way, called path smoothing. Maybe paths with smoothing will help generate some ideas that work for you. The last time I did ...


1

So you need to call renderer.setView(orthoCamera) to reset the tile map drawing view. Then don't forget to also call camera.update() after you do anything to it.


3

Rule number one of multithreading: avoid it. You might think: "Well, there are things in my game which are supposed to happen simultaneously. Wouldn't it be much more intuitive when each thing happens in its own thread?" No, it's not. Using multithreading makes your program magnitudes more complex. You have no control over how much CPU time the operating ...


1

Don't use threads for this. Change "run" method to "update" and just loop through all generators in your mainloop and call "update" for those. I find your logic hard to understand and code hard to debug. This is just my opinion, but threads are not good for this kind of situations. You even have thread sleep in there, so it actually is not that time critical ...


3

Use floating point variables for entities' velocity and position. Use integers only when translating from world position to screen position. This way, your ship will move smoothly thorugh tiles. Also, add a Camera object to convert your world coordinates to screen coordinates as soon as possible.


2

in your Tile.render function you are multiplying the coordinates with the (half) width and height of the current image. But keep in mind that the grid-size of your world is fixed to the size of a normal tile. When you move an object 2 units to the left, its own size is irrelevant. Only the size of the unit matters. Calculate the position based on the size ...



Top 50 recent answers are included