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
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:
...
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
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
You should clearly separate GUI (view) from the actual game state (model). GUI just shows the model to the player (in one way or another) and lets the player control it, but the model itself is solid enough to know everything it needs (level, player, etc). The GUI should know only things GUI needs, which model does not care about (e.g. controls positions).
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
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
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 ...
3
I don't know much about java.awt but from the documentation I can tell you this:
The antialiasing option you are using does not use multiple samples like MSAA and thus does not support the MSAA x2, x4 ... sample counts. The antialiasing method of awt blends the edge pixels with the destination surface by using the exact coverage of the target pixel as the ...
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
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 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
I agree with the people in the comments. It's very hard to do these kinds of things. I recommend looking into Perlin Noise more before you attempt anything. Another thing is to look into Simplex Noise, but I'd start with Perlin Noise, just classier :).
Perlin Noise Info
How it works
This should give you a slight idea about using it
Perlin Worms - This is ...
2
You would probably be better off having your artists produce variations on the default color set, and decide which one to use when the zombie is initially created. The implementation you are using now performs per texel checks to only change a specific color, and say your image is 100x100, that is 10,000 color checks per zombie, on top of the final draw ...
1
This can easily be done just with the bounds of the screen and the position of the sprite. The screen bounds can be stored in two variables, screenMin and screenMax, where screenMin contains the minimum X position of the screen and the minimum Y position of the screen, screenMax does likewise with the maximums.
leftDistance = spritePos.x - screenMin.x;
...
1
Java is an excellent option to start with given the fact that you can put to good use that experience into creating games for Android if you want to. Besides, it's better to start with Java being strong-typed but developer-friendly when it comes to memory management. The best approach is to learn Java and Java2D. You can load your image files but have to ...
1
If C# is an alernative ( it is quite similar to Java ) you could check out C#/XNA. It's very easy to make games in it. It helps you with several topics such as intersection, sprites and audio. But you will handle all the logics yourself.
C#/XNA will be easy to start with. Make a few games with it. If you want to handle more of the game engine yourself, you ...
1
The only way to eliminate checks is to use hardware interrupts.
Then you can write an infinite loop which assumes that it's forever daytime: it does not waste a single cycle checking that day has turned into night.
This loop is executed by a dedicated thread.
When day turns to night, a hardware interrupt goes off. The interrupt service routine responds ...
1
Why not go for a polymorphic approach where your logic is separated into objects with an update function?
You then add these objects to a list and simply loop over this list to update all.
You can give each number a priority so that when you add an object to your list you can sort them easily so that you're sure each object is updated in the right order/
...
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 ...
Only top voted, non community-wiki answers of a minimum length are eligible



