Hot answers tagged java
12
Delete the Thread.sleep() call (assuming you're on a desktop machine and have power to spare!).
In general you never sleep in your game loop (except on Android, where there appears to be no other choice). The bad thing about Thread.sleep is it is unpredictable and may cause your game to give up exec time for longer than 16ms, which is the maximum time a ...
12
Pools are used when the number of objects will fluctuate dramatically and are used to reduce the amount of memory allocation and garbage collecting.
Using a pool the standard new Object() which allocates new memory is replaced with pulling an already allocated object from the pool. This is much faster even if you go though and reset every variable in the ...
8
The main point is that the end user should not be required to install
any Java JRE, nor should the installer contain a JRE and install it
for the user
You can use Java source/bytecode to machine code compilers. There are Excelsior JET for Windows and Linux (requires license) and GNU Compiler for Java which is old.
If it's ok to contain Java with ...
6
Assuming the player index is unique, there's no need to send the name along with it each frame. Send the name + index once, store it in a lookup table on the client, and only send the index in your per-frame updates.
Also, if there are multiple location changes per update, why send the ones that have already expired? Unless I'm misunderstanding the ...
4
you can concatinate 3 matrices
first a translation to put 1,1 at 0,0, then the rotation and then translate 0,0 back to 1,1
if you use affine transformation matrices this is easy
[1,0,-1][0,1,-1][0,0,1] * rotationMatrix * [1,0,1][0,1,1][0,0,1]
if you don't use affine transformations then just subtract 1,1 on each point then rotate around 0,0, then re-add ...
4
The usual answer will be some code that can tweak the random number distribution to give you the properties you want. I'd suggest instead working backwards:
first decide what distribution you actually want and draw it out
calculate the “cumulative distribution” which is the sum of the function in step 1
choose a random number from the cumulative ...
4
The reason why it works in Eclipse is because you are in the project root when you do this:
particleImage = new Image("res/particles/particle.png", false);
For consistency, put your XML file there as well or if you don't want to run it from Eclipse, but from a JAR, integrate an absolute data path in your code (do not hardcode it in your source files).
4
A switch statement, at a very low level, is extremely efficient at this. The compiled code will include a static lookup table in the machine code that will require only one step to go to the correct code block, independent of the number of conditions. Be sure to use best practice with it at all times, (breaks and defaults and yada yada...). My java ...
4
Your second loop example is flawed. You will never want to write code like that because there are many common parts of your game that must run on each main loop iteration. More likely you'd end up with something like:
MainLoop():
while not_quit:
PumpOSMessages()
PreFrameCommonUpdate()
if is_day:
UpdateDay()
else if is_night:
...
3
What you describe is certainly a strange approach to a grid based game. Anyway, there's no way to optimally reference a particular range of your xyz cube of entities without a relational structure containing them such as a 3 dimensional grid array, or something like an octree. Otherwise you're stuck looping through all of them comparing their positions which ...
3
One way to do it is to apply a power function. Start with a random number in [0, 1] and then raise it to the power of some positive number. Powers < 1 will bias upward, i.e. the numbers will be more likely to be higher than lower within [0, 1], and powers > 1 will bias downward. Then use multiplication and addition to shift the range of numbers from ...
3
This is a simple mixing of two different steering behaviors. Following and wandering.
You can find information about implementing both in this GDC paper from '99.
Start with implementing both independently. Then apply both at the same time, with a blending factor. You'll have to modify the blending value depending on how much you want to wander vs how ...
3
Your example is stuffed with bugs and inconsistencies, it is really hard to read, but your understanding error seems to be in sentence 4:
add the origin coordinates back to each resulting coordinate
That is not the original coordinates, but the coordinates of the origin that you are rotating around, so (1, 2) in the example case.
By the way, should ...
3
This answer still ignores the attempt to use matrix rotation, but I realized that there was a simple yet general solution.
First, assuming that the shape is encoded as coordinates of blocks in a grid, you have an arbitrary shape containing blocks with coordinates in the X and Y axes from 0 to n, where n+1 is the maximum size of a block (traditional Tetris ...
3
So, if I understood your problem, you have a way to set an initial state, and a consistent function for advancing the state by one frame. You also have a way to retrieve a current state, but it is not reliable, since restoring to it gives different results than if you had not restored it in the first place.
In that case, I have three options for you to ...
3
If you use a build system like MAVEN it is actually fairly easy to use JOGL. (But it is indeed stupidly hard to configure without it).
Just add this to your POM file
<dependencies>
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen-rt-main</artifactId>
...
2
From your latest comments, it looks like you're trying to save/restore all the internal simulation state inside Bullet (overlapping pairs, contact points, etc.). This sounds... daunting!
Another idea: Every frame, remove and re-add all your dynamic objects. Obviously, this is hugely bad for performance, but you indicated that you don't have many dynamic ...
2
I'm adding this by way of expansion on a comment I made to a previous answer. This question in itself shows a fundamental misunderstanding of what OpenGL is so I believe it's necessary to say more.
OpenGL is not software
OpenGL is "a software interface to graphics hardware" (page 1 of the OpenGL specification until the ARB changed the terminology a little ...
2
You are experiencing a 2D version of a common rookie 3D mistake: order of transformation matters. Matrix multiplication is not commutative, i.e. A * B is different from B * A.
If you translate the Earth to its correct orbital radius before you rotate it according to the 24 hour clock, you will cause the earth to move along its orbital path (rotating a ...
2
There is a bit of documentation on the Net package that gives a very brief overview:
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Net.html The Net.HttpRequest doc covers the http setup in a bit more detail.
The http API is based on callbacks to listeners that handle results or failures. The raw Socket API provides stream-oriented ...
2
(1-1, 3+0) (1+0, 2+0) (1+0, 1+1) (2-1, 2+0)
That's not adding the origin back, that's adding your offset rotation to the initial values.
Adding the origin back looks like:
(0,-1) (0, 0) (0, 1) (-1, 0)
+(1, 2) (1, 2) (1, 2) (1, 2)
-----------------------------
(1, 1) (1, 2) (1, 3) (0, 2)
2
You should describe what isn't working with your code, is it not properly detecting collision? Because then you should look at your collision detection function.
But in general, for 2d you should separate the checking of horizontal and vertical collision. If you do that then there won't be "diagonal collision", just a horizontal collision and a vertical ...
2
Depends on which type of bounding box you're talking about.
Axis-aligned bounding cubes are one of the fastest ways to do a rough first-pass collision test, before sending those that pass to a more precise collision check. Edit: This is especially true when you have multiple moving objects that may collide with one another.
Oriented bounding cubes require ...
2
Prudence
First of all, if you have an if statement that is run once per game loop, don't bother trying to optimise it away, your development time and the extra code complexity is always better spent somewhere else. If you have an if statement that is run 1000 times per game loop, it is probably not worth it either unless you already done all the big things ...
2
Can I just suggest that you absolutely forget about biomes if you can't make and use height-maps yet.
Step by step is the way to go.
A +---+---+ B
|\..|\..|
|.\.|.\.|
|..\|..\|
+---+---+ Y
|\..|\..| |
|.\.|.\.| |
|..\|..\| |
C +---+---+ D ---------x
imagine the +'s as the vertices of your mesh. Simply randomize the ...
1
For Mac, see the Oracle documentation for packaging a Java app for Mac. They've set up Java 7 so that you can bundle the runtime into an application bundle containing your jar files (.app is a folder treated as executable really), which is required for distribution on the Mac App Store. Basically, the .app bundle does mostly the same as what Eren's JAVA_HOME ...
1
Blame me for never having played any of these games, so I can just assume you want your character to turn around while walking rather than turning instantly (e.g. like in The Legend of Zelda games or most JRPGs).
If so, I'd simplify the whole thing using "steering":
Store the current direction the player is facing as an integer. You can either use 4 or 8 ...
1
jogl 2.0 have added profiles, this is important in order to support the new shader only based OpenGL contexts. The base GL class only contain functionality that is still common across all OpenGL profiles.
http://jogamp.org/jogl/doc/Overview-OpenGL-Evolution-And-JOGL.html
To fix your code you first need to request a fixed function compatible profile. This is ...
1
You can solve this by implementing the controller as a state machine with four states:
select character
select action
select target
wait for animation to finish
In each of these state different GUI elements are shown/hidden and the inputs of the user are interpreted differently.
Instead of implementing it as a state machine, you could also implement it ...
1
A common way to do this is to divide the game world into tiles (which is something you may want to do for other reasons too) and have each tile store a list of the items in it. That way, you only have to check the items that are in the same tile as the character (or possibly in an adjacent tile, if the items and/or the character can overlap several tiles).
...
Only top voted, non community-wiki answers of a minimum length are eligible


