Tag Info

New answers tagged

1

When you accumulate deltas you are also accumulating rounding errors. Instead, record the system time the game started and compare it to the system time now. Do not use time-of-day as this can get adjusted by internet-based time-of-day clock synchronization and other things. Different OSes have different names for those clocks. On windows you can use ...


0

I have found the answer for my problem. In order to draw an image and a shape, one can use a pixmap. It is possible to first create a pixmap on which you draw a rectangle. Then, you create another pixmap on which you draw the image. Both pixmap then can be combined by drawing one pixmap onto the other. This is the code I use to build an image containing a ...


1

You could use an ArrayList to store all your stars in. When collision is detected you remove star from array so the star is no longer updated. So : create : ArrayList <Star> stars= new ArrayList<Star>(); add the stars : stars.add (new Star (param1, param2)); update : for (int i = 0; i < stars.size(); i++) { ...


0

The deltaTime is the amount of time which passes between drawing two consecutive frames. It is used for updating things on your screen that change in time, for example when moving your objects around, you would want to apply the deltaTime to the object's speed, in order to have a consistent movement across devices. When calculating playtime though, you ...


2

Touch screen record discrete points with a non-constant rate depending on how busy the CPU is and how reliable the hardware readings are. You need to "connect" those points as lines (old point from last game loop to new point) when checking for collisions and calculate line-line or line-circle intersection (or other type of line-object intersection). You ...


0

Maybe your delta parameter has a wrong value when called. I prefer to use Gdx.graphics.getDeltaTime() instead. float playTime = 0; float playTimeRounded; void AnyUpdateMethod() { playTime += Gdx.graphics.getDeltaTime(); playTimeRounded = Math.round(playTime * 100) / 100.0f; Gdx.app.log("playTimeRounded", playTimeRounded + ""); }


1

In general you can check if any Intersection exist between your two lines as below. Problem: Given n line segments; Report all(as k in algorithms) Intersections. You can implement any of these two algorithm in your desire language and use them. they take your line segments as input and return if any intersection ( Collision in your case) exists. Note: ...


1

Well on your question fixture def, you set sensor true which makes it ignore collisions. fixtureDef.isSensor = true; Unrelated but as a side note, I think you need to dispose your polygonShape at the end after creating everything. polygonShape.dispose()


3

There's no real benefit to sorting those sprites by not-Pokemon index; the texture packer doesn't care what order the not-Pokemon are in, it cares about minimizing the atlas size. I'd just let it do its thing, the atlas file already specifies the position, dimensions, and other settings for each sprite. All you have to do is reference them by name.


1

At some point during your entity logic, you'll have computed the random destination of the entity. Before moving the entity there, check the type of tile that exists at that location. If the type is not desirable, abort the move, or try to generate a new random destination. Often this check is encapsulated in a method on the tile object or the entity ...


2

Yet having these 3500 sleeping static bodies degrades performance to such a degree that even when running the game on my MacBook Pro 2012 in a Genymotion emulator, I get about 5 FPS. As Anko said in his comment, you shouldn't be guessing about whether this is Box2D or rendering or something else. Measure what's taking all the frame time. Use a profiler ...


1

Try sprite.setOriginCenter(); This should help


1

The documentation shows the correct usage of the NinePatch: public NinePatch(TextureRegion region, int left, int right, int top, int bottom) left - Pixels from left edge. right - Pixels from right edge. top - Pixels from top edge. bottom - Pixels from bottom edge. Additionally you can find a tutorial ...


1

Your canCollideWith method should be so that s1.canCollideWith(s2) == s2.canCollideWith(s1)I think. If not it means that collision will differ according to your array order. And if both return the same results you can test that only once. Then in your code, you give two differents definitions of your canCollideWith method canCollideWith(Sprite) and ...


2

The most effective way to improve collision check speed is to decrease the number of entities that needs to be checked against. Spatial partitioning such as octree helps but you can make further improvements. Suppose if currently you have one big list of collidables contains objects and bullets and in each collision check step you are looping through all ...


0

The easiest way to accomplish what you're asking is to split the objects up into different parts and animate them separately. From there you can either use a bone and joint system (similar to what Flash developers do) or, as you said, each part has its own animations.


1

There is no need to update each body when modifying the camera. Bodies' positions stays the same when you move the camera around. batch.setProjectionMatrix(cam.combined); already offsets your batch to the right position. The problem must result of this line : player.body.setTransform(fingerPosition.x, fingerPosition.y, player.body.getAngle()); Assuming ...


0

To solve the alignment problem of the label text I found some information on the internet (where else?). It is possible to add some additional padding to the label inside the text button: TextButton button = new TextButton(text, skin, styleId); button.setSize(width, height); // Add some padding to the label in the button to shift it up a bit ...


0

The problem is that there's two aspect ratios to take into account. You have the aspect ratio of the screen with you're calculating in the aspectRatioHeight method, but there's also the aspect ratio of the image. Consider a image that is 100x100 pixels, and you want to place that with a 10px margin on a screen that is 640x480. If you set the width of the ...


0

You should be using one of the Viewport strategies, all the documentation for it is on the wiki. https://github.com/libgdx/libgdx/wiki/Viewports


1

I would normally just recommend avoiding an ECS and using a more flexible component model that isn't as constraining or filled with as much boilerplate. You can totally put polymorphic logic into an ECS, though, without altering the ECS design itself. One possible approach is to create a LogicComponent and corresponding LogicSystem. This component's data ...


2

Entity/Component systems do allow for unique behavior. This will depend on how you design your components. Components contain data, and systems can change how they process components based on that data. There's no best practice when it comes to designing these things. It's going to depend on the requirements for your game and very much on your coding style ...


1

I have seen two ways of achieving this, one is to let the UserData of the Box2D Body hold the Sprite. body.setUserData(mySprite); And in the update you retrieve that and apply position and rotation to the Sprite according to the Body's transform; Sprite sprite = (Sprite)body.getUserData(); Vector2 position = body.getPosition(); // Center body is center ...


1

You can use the setUserData method to attach an Object to the box2D body (like for example a Sprite or an Actor): body.setUserData(sprite); Accordingly you can get your Sprite back like this: (Sprite) body.getUserData(); Note that you need to cast to Sprite.


0

Go through https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx. This is for Admob may be you can get some help.


2

Track the elapsed time in your Screen, then when a limit is reach as the Game instance to swap to your next screen; public class MyScreen extends ScreenAdapter { private final Game game; private float elapsed; public MyScreen(final Game game) { this.game = game; } public void render(float delta) { elapsed += delta; // Render or ...


0

Try adding Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); to your render function, as still clears the buffer, and alloys the new screen to load.


1

This may not be the answer but, instead of using sprite.rotate(float angle); use: sprite.setRotation(float angle); Hope this helps! :D


0

You can use Path2d to define the outer edge of your rounded rectangle. This actually creates a Shape. To turn this into something you can use, FlatteningPathIterator can be called to create a list of points that can be used to step along the path. You can use this information to draw your circle as it progresses around your progress bar. Here is a good ...


0

A good way to achieve this is using Preferences. Follow this tutorial for more information. Good luck.


1

What values are you using for originX, originY, scaleX, scaleY? maybe you are using wrong values for originX and originY. The origin is bottom left corner of the textureregion as stated in the docs. To set the origin to the center of the texture set originX = currentFrame.getRegionWidth()/2; originY = currentFrame.getRegionHeight()/2; Hope this helps. ...


0

This is just a guess, but I notice that the edges of your image(s) are anti-aliased. When you scale the images down using Linear filtering, the semi-transparent edges might be set to black, because the filter cannot handle semi-transparent pixels. This is just an idea, but it might be worth a try to remove the semi-transparent pixels which surround the ...


0

this is physic. S=Vt , here if t =1 second and s =1unit so it will move by 1 unit/second speed , libGDX render method is called 60 times in 1 second so you can move your character by 1/60 unit each time when render is called and the player will continue to move by 1 unit/second speed


1

You can draw each letter in a new line using \n drawMultiLine(Batch batch, java.lang.CharSequence str, float x, float y) Draws a string, which may contain newlines (\n), at the specified position.


1

this is easy way to create animations, you can add all animation images to one image and than use them separately , for example each image is 20x20 pixel and your animation contains 3 images so the big image will be 60x20 , and if you split it by 20 x20 pixel you can get all the images , and then put those images in animation . Another example. your ...


2

From the documentation: public TextureRegion[][] split(int tileWidth, int tileHeight) Helper function to create tiles out of this TextureRegion starting from the top left corner going to the right and ending at the bottom right corner. Only complete tiles will be returned so if the region's width or height are ...


0

Why not have a 2 dimensional array, of the size of your grid, then draw your pieces depending on how many pixels you have as the dimensions of each grid. For example: public static final WORLD_WIDTH = 6; public static final WORLD_HEIGHT = 6; public static final GRID_WIDTH = 16; public static final GRID_HEIGHT = 16; GridPoint[][] grid = new ...


1

The deltaTime is the time it takes for the system to render one frame, thus if you are using deltaTime correctly, your character should move the same amount regardless of the frame rate. For example, if you are moving your character by the raw deltaTime value (+= delta): If you have 1 update in 1 second, delta will be 1f, and you character will move by 1. ...


0

You'll have to measure elapsed time independently of the game loop. long startTime, time; startTime = System.currentTimeMillis(); while(true) // game loop { time = System.currentTimeMilles(); if((time - startTime) > 1000) doSomething(); }


1

Assuming the board view is from directly above, for simple rectangular boards, you can do pretty well by interpolating from the four corners of the active playing area.


0

When using box2D, the camera you use to render your world should not be your resolution size, it should be your resolution divided by PPM. So when you are making your cam, do something like this: public static final int PPM = 16; //This means that for every meter in your box2D world there are 16 pixels on your camera. If you have a body at position 1,1 and ...


0

You may want to look into tweening, which is what's used to smooth out animations using various smoothing functions. If you don't wish to implement anything yourself, you may want to look into: http://code.google.com/p/java-universal-tween-engine/.


0

It's a problem with JAVA apps being scaled twice by retina displays. I presume your talking about the desktop version right? I currently have the same issue, it's super blurry. The solution is to turn off retina scaling for java apps, currently trying to figure this out.


1

TextField has a method called getText(), it may never be null but may return an empty string. txtUsername = new TextField("", mSkin); txtUsername.setMessageText("test"); txtUsername.setPosition(30, 30); mStage.addActor(txtUsername); String test = txtUsername.getText(); System.out.println(test); ...


5

It's because you're doing integer math in the first case, but not in the second. First, a quick look at the documentation getWidth int getWidth() Returns: the width in pixels of the display surface. < getHeight int getHeight() Returns: the height in pixels of the display surface So now we know that the two methods return integer ...


0

First ensure that your Actors are able to report their bounds: public class Enemy extends Actor { Rectangle bounds; public Enemy() { bounds=new Rectangle((int)getX(), (int)getY(), (int)getWidth(), (int)getHeight()); } public Rectangle getBounds() { return bounds; } private void setXY(float pX,float pY) { ...


1

dNot sure if a more specific answer is needed here, but for me to fix this issue I had to adjust the projection matrix on the SpriteBatch. Although destroying the SpriteBatch and recreating it would also work. So in my constructor I create the camera: camera = new OrthographicCamera(); Then when the size of the window changes I execute: ...


0

Found the answer, instead of the static Table.drawDebug(stage); call there is an instance method called stage.setDebug().


0

In the inner for loop, shouldn't you be incrementing k instead of i? You're doing i++ twice, so at some point, your code is trying to access Main.currentBullets.get(10), which is causing your Index 10, size 10 to get thrown.


0

Like you said, you need a scaling factor. float scaling = // some number. Probably something like 100 will do for Box2D. public Vector2 metersToPixels(float xMeters, float yMeters) { return new Vector2(xMeters / scaling, yMeters / scaling); } public Vector2 pixelsToMeters(float xPixels, float yPixels) { return new Vector2(xPixels * scaling, ...



Top 50 recent answers are included