Tag Info

New answers tagged

1

yeah, all solutions have already been made... i'll just add some more code (i'm rather from stackoverflow ^^) assuming you're using bounding box assuming you use plain java (java.awt) . List<Shape> shapeList = ...; //you know where you get them Shape exampleShape = shapeList.get(0); Rectangle2D boundingBox = exampleShape.getBounds2D(); see ...


1

Imagine the radius is one. That means every point around the circle is exactly one unit away from the center. Now what kind of vectors always have a length of one? Unit vectors of course. You can get a unit vector by normalizing a non-unit vector. Take the vector CA (center to A). Next, normalize CA to make it a unit vector, then scale it by the radius of ...


1

If you know the canvas is a rectangle then this simplifies to the case of checking if the bounding rectangle of the shape being drawn is contained within the canvas' rectangle. That's a fairly efficient check to run, and (generally) finding the bounding rectangle for your shape should be fairly easy (just finding the minimum and maximum x and y coordinates) ...


3

As already pointed out in the comments and answer: This can be arbitrarily complex. Particularly, depending on the exact use case and performance requirements, you can employ some rather sophisticated data structures in order to make these tests fast. The bounding box test is the simplest one that should be done in any case (and in fact, could already be ...


1

One obvious solution is to store the entityId inside each component structure or class. This way when you need to obtain components or do some entity-specific logic, you already have an easy way to obtain the entityId based on a given component. Another solution that may be a tad more complex but has some useful side affects is to assign each component a ...


5

I have good news and bad news for you: The Bad News: I don't know or remember any Java library that does what you want The Good News: It's really easy to implement this type of algorithm yourself! Here's a couple, you can mix them to optimize your collision detection depending on the type of shape. BB Collision Detection You can imagine a box around ...


0

[EDIT: as I don't know what lib you're using, and as this question is not specific to Java, my answer is in pseudo-code.] If I understand your question correctly, atan2 is not what you're looking for. What you want to achieve is moving something (which has coordinates) from one point to another according to time. You just need to compute the vector between ...


0

Suppose the projectiles curret position is $(x,z)$. Then, in each step, you let $x_{new} = x_{old} + t \cos(\theta)$ and $y_{new} = y_{old} + t \sin(\theta)$ where $\theta$ is the angle you found, and $t$ is some small number (depending on the number of milliseconds since last update, for example).


0

I have to say that the current build JavaFX 8 is very well suitable for professional games at least for 2D. The big advantage is that JavaFX has a very professional GUI library which makes it very suitable for UI heavy games.


0

Edit: just realised this is pretty old. Anyways, I did something similar to this in a TD game so hopefully the same would apply here. In my TileMap class I have a method called getTileCoord(int mouseX, int mouseY) and for your game it would be translated to something like this: int tileX = (int) (mouseX - camX) / tileWidth; int tileY = (int) (mouseY - ...


2

It means desktop. You have two options to deploy your libGDX app to the desktop: Create a self-runnable JAR. This is easier (Eclipse can export it pretty easily). Create an EXE, via launch4j (or some other wrapper). This is possible too (especially with Gradle). I've used both approaches and they work equally well as far as I can tell. Both rely on ...


0

Well this is the way I did it (May not be the best solution): Requires two booleans, a and b. If the key is down, and a is false, then start the animation, and set a to true. Then, if the key isn't down, set a to false. That way the animation will cycle through once per click of the key. Depending on what engine you're using, you may have to do something to ...


1

The setLinearVelocity method literally sets the Box2D body's x- and y-velocities to the given values. That means if the parameter for x is set, the character will begin moving horizontally. However, if the parameter for y is zero, the character will stop moving vertically. To fix this, you could either pass the character's current y-velocity in the ...


0

I don't know if this is the Problem, but your LibGdx.onCreate() is calling LibGdx() which calls the onCreate() again.


0

Create a drop rule: here are my assuptions: you have a round based game you have a method that handles input (best case: as a command) you have a list for monsters and a currentMap when will a drop rule apply? at the beginning of the monsters turn: //assuming you have a kind of listener that handles all inputs public void parseInput(Command cmd){ ...


2

Your flag should be an indication of whether to start the animation, not whether to continue playing it. e.g. if (IsKeyDown() && !pressed && !animation.IsPlaying()) { // record that we triggered the animation pressed = true; // start playing the animation animation.Start(); } else if (!IsKeyDown()) { // we reset our pressed state ...


1

@wondra's comment that anything that does damage is a Weapon is spot-on. Don't get confused by having the class name be restrictive when it's not the right word. Perhaps in this case you want the class to be DamageDealer instead of Weapon. Another, and better, option is to use interfaces for the object types. This way you get a broad hierarchy instead of a ...


0

glDepthRange (1, 1); Job's a good 'un, done.


-1

the size doesn't matter so much as does the texture that you are applying to the skybox (at least so long as its bigger than your playspace, there are apps out in the wild that will help you create skybox textures with seamless edges. If you are looking to use procedural generation your skybox, you have to do some flat to spherical projection so that as you ...


2

Your server is more authoritative than it needs to be. The client needs to start moving as soon as the button is pressed, so there is no perceived lag. The server can then essentially replicate packets for other players, (maybe run a physics-sanity-check against a stored world model to prevent cheating, like warping through walls and such). Time stamping the ...


0

If you can make the ball travel to the center of the vortex, you have half the answer. In potential flow theory, this is known as a sink. The other half of the answer also comes from potential flow theory, where you can make use of the irrotational vortex: "Irrotational vortex" by Silver Spoon is licensed under CC BY-SA 3.0 The equation describing the ...


0

AABBs (Axis-Aligned Bounding Boxes) are (as the name suggests) without rotation. What you need are OBBs (Oriented Bounding Boxes), there are many tutorials on the web but collisions in 3D space are always either not good enough ore a pain in the back. Wikipedia provides a nice set of formulas ;) ...


7

In order to get a server list, you will need a central matchmaking server to which all game-servers connect and announce that they are online and to which all game-clients connect to obtain the list of currently online servers. How many servers are you going to have? For comparison, I remember that during the high-times of the original Counter Strike, the ...


0

My answer might be too shortcomed if I am missing something, but if all you want is to add additional force to spin things in a vortex way, all you need to do now is to act another force on each of the affected bodies, which goes in the tangent of the angle between it and the vortex center. So, if angle is the radian angle between the vortex center and the ...


1

For simple matchmaking only, you can create an ASP.Net or PHP website that the players login to (via your game app) and push a notification when they create a server. The problem is securing the server to make sure only your players are accessing critical services like advertising a host or requesting the available host list. There are also services like ...


4

EDIT Actually, Timer's schedule method should work in this case - maybe it's running straight away because you have 100ms as your delay time instead of 1000 (from your code above that is). If you're working in a multi-threaded environment, then make sure you handle possible concurrency issues. A possible alternative would be to use System.nanoTime() ...


2

Before anything, I'd look for a heap profiler and make sure it's the GC that's causing problems. However, if you find that it is indeed the number of objects you have in memory, you've already come up with the basic solution; page your chunks out to disk once in a while and only keep nearby ones in memory. But, as you've seen, there are problems with the ...


0

The good news is that constant width Gaussian filter is separable thus you can gain good performance even for large kernel sizes, i.e this cuts the computation from the naive O(n^2) cost down to O(2n). The separable Gaussian filter is implemented by having two passes over the image: First performing 1D horizontal Gaussian blur, followed by 1D vertical ...


0

You can call .setText("Some String"); on your label in your Render-method.


2

I'm assuming you're using the standard Java 2D API, not OpenGL. In that case, you render your graphics to a buffer image first. Then, to render that image to the screen, you can either use a Graphics.drawImage call that allows resizing your buffered image: public abstract boolean drawImage(Image img, // the buffer image int dx1, int ...


0

As others have pointer out, you should generally prefer composition over inheritance(is-a vs. has-a): public class Creature { private Inventory mInventory; public boolean hasInventory() { return mInventory != null; } public Inventory getInventory() { return mInventory; } public void setInventory(Inventory ...


1

Oh man- I've implemented this a time ago... The map is divided into map chunks - I've created separate files for each map chunk... a map chunk consist of 32x32 tiles in my implementation, you may vary on this whenever the player (centre of red X) is moving inside a chunk you can detect if the player is moving from one chunk into another... // Depending ...


3

In general you should prefer composition over inheritance if answer to question "A is a B?" is "No". E.g. Inventory is a Creature? No, then it should be a component. But Vampire is a Creature, so it's logically inherited. My other answer to similar question can also be useful.


3

An Inventory class with a matching field on the abstract class Creature seems best. You can perform a null check against this field to see if a creature has an inventory. This also allows you to reuse the inventory class as a field of non-creatures like bags, chests, rooms or anything else that suits your game.


2

This might be too late for you, but for the benefit of web searchers, I'll answer: Create an empty canvas (AWT). Set the size of the canvas to be equal to the LWJGL Display. Add the canvas to the Java Swing form. (There's a reason for this). Set the canvas as parent of the LWJGL Display using Display.setParent(canvasName);. (Remember you might also need to ...


1

Look at what's happening. SaveX is 300, SaveY is 0. When you normalize moveVec you take the Vector (300,0) and resize it to be a length of 1, which makes it (1,0). You test to see if 300 > your position, if so you add moveVec.getX(), otherwise you subtract. So you move 1 to the right. You then test to see if 0 > your position, if so you add ...


2

I know this is old, but I finally discovered the solution. In my game, I am using g.translate(x,y); but I was using a float for the x and y values. So I did this: g.translate(Math.round(transX),Math.round(transY); Now there are no more vertical lines! Hopefully this helps anyone else with this problem.


1

It depends a lot of how your game actually works, but in most games it is not necessary to send all positions of all objects after every frame. In most cases, most of the information will either not change right now or will be changing in very predictable ways (like an object moving in a straight line). It is often a lot more bandwidth-economic to only ...


2

From my knowledge using the Serializable language feature for realtime game networking thats running at 40+ FPS is very bad. I would send data in a plain binary stream for example Ive got to send the following variable in a class... (String) player name, (Integer) player health, (Integer) player model id, (Integer) player x, (Integer) player y I would ...


0

To your 3rd question, yes, you could preload the necessary models and just update positions and whenever a new players connects, load the extra info (you could do this asynchronously so as to prevent lag spikes). You could also calculate movement cycles (animations) on the client or on the server and then send the player's current animation 'step' to the ...


1

To expand upon my earlier comment: For a 2D tile map, I don't usually see any need to stream the map into memory, or load it by chunks. The easiest gains will come from simply not rendering any tiles that are off screen, and not updating any entities that are more than X screen size units away. If the map is truly massive, to the point that you can't ...


0

I'm not too sure if I understand the question correctly so forgive me if my answer if off, but this is how I would go about a turn-based event system. Firstly, the actions that are represented by strings and ids can be converted into something more object-oriented which would be something like: public abstract class Action { public abstract void ...


1

Ok the obvious stuff ... Remove all the timeout calls. Remove the Thread.Sleep() calls. Have you tested just this code on its own? How do you know its "slow"? Are you sure the code that reacts to this isn't slow? Why are you creating a new connection on every send ... The process should be ... create "connection" / stream reference. send, send, send. ...


0

If i understand this correctly then you take some data and then as part of the rendering process you distort the postition of that data ... this.camera=new OrthographicCamera(); this.camera.translate(map.getMapPixelWidth()/2, map.getMapPixelHeight()/2); this.camera.update(); view=new StretchViewport(map.getMapPixelWidth(),map.getMapPixelHeight(), camera); ...


1

I'm currently writing a text-adventure myself and choosed the following (unoptimized, clumsy ect.) approach. Why is explained in the conclusion of the answer. For the short version, skip to the end of the answer. My game is structured in areas which contain locations. A player can have roles which allow him to do something (or disallow him from doing so). ...


0

ouch ! ... eventing is normally pub sub ... I say "this happened" and you as a handler go "ok now i need to do ..." this presumably is like some sort of action list system in which case I would implement it as such. Does java have lambdas yet? I would have somehting like this in c# ... class EventManager { List<Action> actions; void ...


0

Ok the question is pretty vague in that it reveals nothing about your game design but here's my take on any form of "game world": You painted a picture of this in my head .... public interface IArea { public void Enter(Character newChar) { ... } } public class World { public List<City> Cities { get; set; } } public class City : IArea { ...


0

You can start by doing this ... I can load new tiles but how do I load new chunks? Once you have that in place you can then choose what chunks to render by using some basic positional logic like "get me all the chunks with tiles between pos1 and pos2" pos1 and pos2 can be simply determined like this ... pos1 = char.Position - renderDistance; pos2 = ...


0

Cities are the same as the rest of your environment. How do you define it? I think your 'rooms' are styled different - some with treasures and some with monsters. So your cities have some rooms with shops and some with parks. For me, it is the same approach.


1

A good rule of thumb is to have your content be data driven. You would store this data externally and create a class to load in the data. There are lots of reason to do this, such as You don't have to recompile when your data changes You can use Excel or a text editor to edit the data. The data load can be abstracted from the data itself



Top 50 recent answers are included