Hot answers tagged

9

It won't hurt performance. It might in fact be (very, very negligible) faster because you save the overhead of passing these objects to the game objects. The reason static classes are often frowned upon is that their static properties are global variables and globals cause all kinds of problems architecture-wise. For example, when you ever decide you might ...


4

I use the libGdx Json functionality to save my game state to JSON; public class GameInstance { //Some fields, constructors, utilities public void saveState(GameState state) { String save = json.prettyPrint(state); //Save to the file using FileHandle } public void loadState(FileHandle file) { String ...


3

If you're definitely only ever going to have one instance of these objects, and presumably you are, then this would be a better way to go. However, maybe a better solution would be to use the Singleton pattern, and (for example) create a static GetScreen() method in the Screen class that any other class can call to obtain the single instance of the Screen ...


2

I had the same problem while searching for funnel algorithm. Here it is a summarized procedure, considering one origin and target point: Triangulate your polygon Select origin and target points find origin and target triangles Do any graph search algorithm to find the path of triangles from origin to target find the path of edges connecting the triangles ...


2

The parameters control which axis the image will be flipped around; sometimes you only want to flip around one or the other axis, instead of both. The first parameter, if true, causes the image to be flipped in the X direction (horizontal flip) The second parameter, if true, causes the image to be flipped in the Y direction (vertical flip). If both are ...


2

Yes. For 2D sprite-based games, AWT can be used to handle the rendering to great effect. It can even be hardware accelerated, depending on the available hardware. Without any code or detailed profiling snippets, it's hard to say what the issue is. Best I can do is offer some basic tips for working with Java and AWT when building games. Working with the ...


1

The nice thing about the Factory pattern is that the base class can be abstract and you can have different derived Factory classes. That means you can have an ExplosionFactory, a BulletFactory, an EnemyFactory and so on, which all inherit from the basic class GameObjectFactory. Any code which is common to all objects would be in the GameObjectFactory while ...


1

function newLevel() { if (ModPE.readData("firstLaunch") != true) { ModPe.saveData("firstLaunch", true); clientMessage("This is the first launch"); } else { clientMessage("This is not the first launch"); } }


1

I don't know android specifically, but if you are using OpenGL ES, you can use a shader to make this work. First create a image like this in black color. Then use a color tint. Now use a fragment shader to draw this texture. The code looks like this. #ifdef GL_ES precision mediump float; #endif varying vec2 texCoords; uniform vec4 color; uniform ...


1

Your whole matrix is incorrect. For example, this is one of the ways it should look like: So, in code: dest.m00 = 1.0f / (tanHalfFOV * aspectRatio); dest.m10 = 0; dest.m20 = 0; dest.m30 = 0; dest.m01 = 0; dest.m11 = 1.0f / tanHalfFOV; dest.m21 = 0; dest.m31 = 0; dest.m02 = 0; dest.m12 = 0; dest.m22 = -(far + near) / range; dest.m32 = -2 * far * near / ...


1

I assume that you are calling update() once every frame, before you draw the frame. Your problem is that you are doing either the collision correction or the movement every frame. You need to do both. What's happening is: Your character checks if it is below the screen bounds, it isn't So it moves below the screen bounds, draws for one frame below the ...


1

Ok, after 4 hours of searching finally I found the mistake. Problem was with the sprite origin. Here's the line that was necessary (staticBody is the body around other bodies will rotate) tmpSprite.setOrigin(staticBody.getPosition().x / 32 + tmpSprite.getWidth() / 2, staticBody.getPosition().y / 32 + tmpSprite.getHeight() / 2); And here's ...


1

I found my issue after getting some sleep, I forgot to take care of the parents in the CollisionComponent. All I had to do is to iterate up in the entity heirarchy chain (scene graph nodes) and apply the parent transforms to the polygon. // Get some temporary Vector objects to work from the object pool Vector2 tPosition = Vector2.REUSABLE_STACK.pop(); ...


1

This is the while loop above redone. Kind of ugly and repetitive but it works. I had to use Math.floor and Math.ceil to solve the collision issues which is due to precision I guess. Any spare dt left over if the action sequence is finished is discarded so that might be something to save for accuracy but the timesteps are really small so it may not be ...


1

Math.cos uses radians, not degrees. You want to go from 0 to 2* Math.PI You could do that like this: if (Keyboard.isKeyDown(Keyboard.KEY_D)) { if (i < 360) { //Convert to radians by multiplying by Math.PI*2f/360f float theta = Math.PI * 2f * (float) i / 360f; setX((float) (groundState.getX() + groundState.getRadius() * ...



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