New answers tagged

0

The character should have a single state machine. Animations should be controlled by the character state so they don't need their own character-specific state machine except as part of a generic animation system. Status variables (health, ammo, invincibility timer, inventory, etc) are part of deciding which state to transition to but not state machines in ...


0

A favorite way to apply camera shake in 2D (or 3D) is to attach the camera's origin to a physics particle, then to attach the physics particle to the focus of the scene with a heavily-damped spring. This allows for adding variable camera shake quite easily, in any direction you want, by adding momentary acceleration (a poke) to the camera's physics particle. ...


0

an engine agnostic way to do it is to use average light mapping. First, you need to generate a black and white map as a 2D array of booleans that is the size of the world where the blocks are True and empty is False. Like This(1 is black, 0 is white): Then you need to create a new 2D array that is the same size as the first array but is an array of ...


2

The relationship between the Gun and the Bullet is purely 'spawner/spawned'. It's not parent-child. In real-life, when you shoot a bullet with a gun, both objects are no longer linked: you can move the gun as you want, once the bullet is out of the barrel, there's nothing you can do to change its trajectory. So in your case, you should make the bullet as ...


3

A simple way to achieve smooth lighting in a tile based game, is to draw a "lightmap" to a render target, and then drawing this render target over top your scene while alpha blending it. Your light map render target would be the size of your tile map, but in pixels. Each pixel would represent the light color of its corresponding tile. This render texture ...


0

For now this is the way I handle AI messaging with ashley ECS in libgdx. TelegraphAgent implements Telegraph { StateMachine fsm; public TelegraphAgent (StateMachine fsm) { this.fsm = fsm; } @Override public void handleMessage(Telegram msg) { fsm.handleMessage(msg): } } AIComponent implements Component { ...


-1

There are plenty of trade offs to make in selecting a language. For example, C++ is known for being much faster and more efficient than a language like Python. However, it can also be more complex and difficult to build. If you are brand new to making games, I would recommend using Unity and programming in C#. Unity also offers some good native tools and ...


0

I'm aware this is really late and you've probably already solved the problem but for future readers: This forum post helped me: http://badlogicgames.com/forum/viewtopic.php?f=11&t=12343 If you move the camera while part way through a pan or ANY gesture the coordinate system being used for the x and y coordinates is changed and that's why you get the ...


0

If only there was a magical place where you could look up things like this. https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ImageButton.html#draw-com.badlogic.gdx.graphics.g2d.Batch-float- I wonder if that button classes draw routine could help. Hmmmmmm.


1

First tip, don't use a linked list. At least not in this way. Use an ArrayList instead. If you absolutely have to use a linked list use an iterator. Secondly it's probably a good idea to cull stuff on your screen. That should get you going for a while. Although I am willing to bet there are performance issues elsewhere as well.


1

From the libGDX github wiki: Note: By default, the Json class will not write those fields which have values that are identical to a newly constructed instance. If you wish to disable this behavior and include all fields, call json.setUsePrototypes(false);.


3

SurvivalMachine nailed one of your problems (you can see that the texture is repeated twice). Your other problem (the texture is a big blob instead of a crosshair) is because you don't use transparency : some of the completely transparent pixels of your texture have a green color value (that's a common sight with optimized PNGs). Just enable blending with ...


2

Maybe there's more problems, but at least this looks incorrect: gl.glTexCoord2f(2f, 1.0f); Your texture is repeated horizontally 2 times because its wrap mode is repeat and the coordinates you set are over 1 (in this case 2f). To fix this, replace 2f with 1f: gl.glTexCoord2f(1f, 1.0f);


0

public void run() { long beforeTime, timeDiff, sleep; beforeTime = System.currentTimeMillis(); while(true){ coin2.move2(); //move the 2nd coin based on the inputHandler repaint(); timeDiff = System.currentTimeMillis() - beforeTime; sleep = DELAY - timeDiff; if(sleep < 0) sleep = 2; ...


0

LWJGL is a low level framework that includes window creation, input handling and other low level features. Libgdx is a full featured 2d and 3d game framework that is built on top of LWJGL. The typical workflow for drawing a triangle on screen with LWJGl is: 1- Create a window using the included GLFW3 framework. 2- Create an Opengl context using the built in ...


0

LWJGL is Lightweight Java Game Library. It is not engine. LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL), audio (OpenAL) and parallel computing (OpenCL) applications. This access is direct and high-performance, yet also wrapped in a type-safe and user-friendly layer, ...


3

LibGDX is based on LWGL and its advantage are that a lot of the base stuff is already written and you don't need to write it. Some people prefer to write it themselves though. LibGDX is generally used in mobile game development, but can also be used on Windows, Mac and Html. Some final words: For beginners I would suggest using LibGDX, because it is easier ...


0

Strange bug, after slight editing of image, and saving image as png again, exception dissapper. During debug of application i saw TExture constructor call PixMap constructor and send FileHandle of file as argument, constructor read bytes from image (dont know correctly or with errors) then those bytes go to Gdx2DPixmap(bytes, 0, bytes.length, 0) and that ...


1

I found that the reason is my event queue realization and the second reason is that I use OS cursor (OS cursor is hardware accelerated). Mouse position is current mouse position obtained from GLFW, lag - difference between current position from GLFW and from event system. Here is approve:


0

I am also picking tile variations based on a tile's eight neighbors. Encoding the neighborhood is fairly simple, but deciding what pattern each set of bits represents is kind of tricky. I currently just have collections of matching ints for each pattern, and I am checking each pattern type for containment. I do have the impression that a Binary Trie could ...


2

So, you say, that when you update the cursorPosition variable you update the cursorPositionPrev variable too. This is not a good idea and this could be one of the reasons why it goes a bit slower than your mouse. Your update method gets called 60 times per second, but the mouse listeners can run way more times in a second. So, let's imagine this: your ...


1

I'd try to avoid using any form of event dispatch within an ECS. From the looks of it you're trying to change state based on some kind of input. I assume that block of code where you track input is inside a system. So instead of dispatching an event why not just update the requisite components directly from that system. Systems can process multiple types ...


0

If I'm not mistaken, you want to create a pool of different monster without creating many pools? If yes, just create a MonsterPool that extends Monster public class MonsterPool<T extends Monster> extends Pool<T>{ } public MonsterFactory<T extends Monster> { Array<T> activeMonster = new Array<T>(); MonsterPool<T&...


2

The short answer is that you can't return different subclasses from a Pool. Even if you used a static variable to pass parameters to newObject(), newObject() is only called when all of the pooled objects are already being used; meaning that you would never know which subclass you are getting when you obtained a pooled object. Before continuing down this ...


0

There are a lot of different kinds of transition. To concretely answer this question clarify which kind of transition you are looking for. If you want to do a blended transition, you'll need to render a single frame of the old scene to a buffer, render a single frame of the new scene to a buffer, and then do the transition animation. Here's a pointer for ...


0

You are totally defeating the purpose of using an Entity-Component-System by creating that Character class. The whole drive behind ECS architecture is the decoupling/separation of data(Components) and logic(Systems). What you need to do is create separate Systems to handle attack and movement logic. Read these two articles, they'll help you get a better ...


1

If you zoom the second image - you can see that green square rendered twice and on it to, so probably you have two draw calls for your green square...


2

If you want the simplest method you could just use something along the lines of a Factory: public class CharacterFactory { public static Entity spawnCharacter(PooledEngine engine) { CharacterComponent character = engine.createComponent(CharacterComponent.class); TextureComponent texture = engine.createComponent(TextureComponent.class)...


2

Your intuition is correct, the easiest way to do it would be to normalize your vector, and then rescale it using the Projectile.maxSpeed. If you need the angle for some reason, you can get the direction to the target by using the atan2, which can be used to convert an x and y difference into a rotation. Here's some C pseudo-code to show you: float x_diff = ...


1

It may seem redundant to have a position component when the Sprite class has x and y properties but this is actually a very valid setup. First, instead of calling it a SpriteComponent lets call it a DisplayComponent instead and implement it as follows: class DisplayComponent implements Component { Sprite display; } The context of the component is now ...


1

A guess (too long to put in a comment): If spotFactor becomes 0.6 at a specific pixel, from this float spotFactor = dot(lightDirection, spotLight.direction); then color goes negative here (as you said spotLight.cutoff is 0.71): color = calcPointLight(spotLight.pointLight, normal) * (1.0 - (1.0 - spotFactor)/(1.0-spotLight.cutoff)); will ...


1

There is at least one serious problem in the code. In calcLight(), the test below is invalid. Calling pow with a negative first argument is undefined behaviour, so you need to test specularFactor sooner. float specularFactor = dot(directionToEye, reflectDirection); specularFactor = pow(specularFactor, specularPower); if(specularFactor > 0) ...


4

Unexpectedly black pixels sometimes indicate that you've got an infinity or NaN in the shader somewhere. For example normalize(vec3(0,0,0)) will generate a NaN. To me, the most obvious candidate in the above shader is the reflectDirection variable, but I could be wrong. GLSL has isinf() and isnan() functions that you can use to detect those cases. If that ...


1

Everytime you move the sprite, move the camera too. This sounds like it's essentially what you're doing now. If you're encountering performance issues, then you should profile your code to determine where your slow code is. If you're not seeing performance issues, then you don't need to worry about performance issues. Doing a few calculations every frame to ...


0

I'm assuming you have paintComponent() already set up. You just need to use java.util.Timer and java.util.TimerTask. Timer is a class that runs a method implemented in TimerTask after a delay. TimerTask is an abstract class that allows you to implement the method that Timer runs. The function that Timer runs is TimerTask's run(). In TimerTask's run(), you ...


0

You might consider packr, one of the libgdx tools. From the project's read.me description, it Packages your JAR, assets and a JVM for distribution on Windows, Linux and Mac OS X, adding a native executable file to make it appear like a native app. Packr is most suitable for GUI applications, such as games made with libGDX. You can specify the JRE you ...


0

How many times are you calling render from the Tile class? Because every time you do it adds 5 new enemys. If you are calling that render method a lot then I would suggest moving the for loop to the constructor.


1

OK, assuming that render() gets called once per frame you are telling your game to create 5 new enemies every frame in the tile class. This would lead to creating hundreds of enemies per second. I think you only want to use that for loop once when initialising the game. That way you will only make 5 (until you decide to make more). look in the ...


2

to remove class information, use fileJson.setTypeName(null) to display all infomation including default value (in your case "false" is default of boolean), use fileJson.setUsePrototypes(false); see more in documents


1

You've got two simple options: Generate particles based on the velocity of the sword in the form of motion lines Draw up sprites and iterate through these using frames (couple of examples at http://www.spriters-resource.com/genesis_32x_scd/shinobi3/sheet/20808/)


0

The answer lies in here : shapeLabel.setTouchable(Touchable.disabled); With this I am able to achieve what I intended to do. The other alternative I found is to relay the events using InputMultiplexer. But, I felt the above solution to be simplest.


0

Result: it's not possible. surfaceView.setZOrderOnTop(true) will cause SF to be on the very top, so you just can't draw anything over it. And with setZOrderOnTop(false), you can put views over SF, but its background won't be transparent (and that's what I need too..). And that's quite sad.


0

I've seen multiply ways this was done in the past. Most of them failed and none of them were good enough to jump across this obstacle completely. Everyone of them has some flaw in it. I post the 3 most sucessfull ones: Start a separate server using java and make it generate the worlds for you. With java you can start another server in the same folder, and ...


1

Very strangely, it appears that your picture is not transparent. I copied your code, and tried it with your image, and the background was white. Then I tried it with a png I found on my computer and it did work. So I put your picture into photoshop, and there it was – a white background. Here's a transparent version if you need :


0

The stretching is occurring because each circle that you add is getting moved down four pixels every time. For example: Take this array: { } It will hold the Y coordinate of every circle. Your beat tracker reaches a beat on he lost and adds a circle. Let's put that circle at 50 y. The array now looks like this: {50} After adding the circle,...


1

Tic-tac-toe is a great target to try to write an AI when learning a new language. These steps are proven to maximize your chances in the game. You always draw with perfect play of both opponents and win if opponent makes a mistake. You should check these conditions in the order they appear: (1) If this is the very first move - take a corner (or the center). ...


1

If you're going to use two images anyways, why don't you simply just have one image without an outline and one with an outline and just swap between them? As for other methods of drawing an outline, it can be done using multiple methods. If you're going to draw an outline on simple textures (let's say a square) use a ShapeRenderer (docs & tutorial) and ...


0

Instead of the this you need to pass an instance of the main class to the method. You can achieve this by using the constructor. When you create the Listener class (wich shouldn't be named listener BTW) you need to pass the instance of the main class to it. //Listener class <Main class> instance; public Listener(<Main class> instance) { this....


0

DISCLAIMER: I am still a newbie when it comes to ECS so do not consider the following as a definitive answer To me it seems that a bullet should be an entity instead of a component since it probably has to be rendered (unless you're taking the hitscan route) and has to interact with the world a.k.a. physics. As for pooling, it depends on what has to be ...


0

It seems like you are going about this the wrong way. Linear interpolation is the process of transitioning from one value to a second value, which is exactly what you are looking for with your movement. I'm unaware of java and libgdx syntax, but here's some example code so you get the idea. Here's what you need: Vector2 CurrentPosition : Your characters ...



Top 50 recent answers are included