Tag Info

Hot answers tagged

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


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.


3

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


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


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


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


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


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


2

as written in their wiki: If continuous rendering is set to false, the render() method will be called only when the following things happen. An input event is triggered Gdx.graphics.requestRendering() is called Gdx.app.postRunnable() is called in LibGDX every input event (mouse move, button pressed), the render function will be called so, ...


2

Don't follow the guidance of Ion Farima. This is plain wrong and not secure. The correct way of handling this is via a webservice (REST, SOAP, protobuff, whatever suits your needs). Your app/game connects with the webservice, sending the required data (+ using salted MD5/SHA1 hash of the data with other stuff required to identify the user (i.e. unique user ...


1

if i get this right, you are trying to get the "game world" pos from screen pos, as mentioned in their wiki- // x and y are your screen coordinates // (e.g. where a click/touch happened) Vector3 worldCoordinates = new Vector3(x, y, 0); camera.unproject(worldCoordinates);


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++) { ...


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


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()


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


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


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.


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


1

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


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


1

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


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

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


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


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

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.


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


1

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



Only top voted, non community-wiki answers of a minimum length are eligible