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.


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

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

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

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

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

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

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

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

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

Try sprite.setOriginCenter(); This should help


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


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



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