New answers tagged java
0
Your problem is that you are doing the update logic in keyPressed() method.
When you press a key, AWT will call this method once. After a delay (typically 250-1000 milliseconds) it starts calling this method again repeatedly with a smaller delay (typically 30-400 milliseconds). When the key is released, this repetition stops and keyReleased() method is ...
0
One problem I see with this code, is that it doesn't check if the keycode is in range. I usually make my boolean array to be 65,536 (216 or 2 bytes). Then in the onPressed method, I check if the code is in range. If it is, I set that code to true. This is how I usually code my KeyListener onPressed method:
public void onPressed(KeyEvent e)
{
int code = ...
0
I take it that you are keeping an array or an ArrayList, maybe of booleans, that records key states and have some key listeners that modify that. It's hard to see what else, given the limited snippet of code.
Just make your game loop, thread, etc implement the KeyListener interface, unless that is that what you are doing. I think the motion being fluid or ...
0
Possible cause :
From your code, no visible sources of lag are present. The lag may come from the way they are accessed from the game loop thread. Dont forget, the variables have to be synchronized, or you have to use locks for your app to be thread safe.
The lag you experienced may be from the fact that you increment the x and y by 5 each. I am guessing ...
0
The answer to your specific question, how does the GUI know about the level being played, is: it doesn't.
The GUI displays everything it's being told to display, but it doesn't have any information about what that data actually is.
A common approach is to use a message system to pass messages from one component to another. When the LevelLoader has finished ...
3
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).
0
Evan is right if you have the artist bandwidth, otherwise, you could make this algorithm a lot more efficient. The issue you have is that you're twiddling individual bits in about the most expensive possible way you could.
Right now, you're testing each pixel individually to see if it's blue and changing it if it is - however, you said that you're drawing ...
0
You could reserve a certain color value in your image to be the "tint color", something you are unlikely to actually use like (0, 255, 0). Then create a function that copies the image and loops through all the pixels, every time you find the tint color replace it with some other color using setRGB().
Then for each zombie variant, create a new variation of ...
0
Evan seems correct. It may also be possible to divide the zombies into two textures; one consisting of any parts of them not likely to change color (ie, skin) simply floating in midair, and another for parts of them that may change tint (ie, shirt). You could draw these on top of each other, and specify a tint color only for the second texture in the ...
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 ...
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 ...
0
I would approach the problem like this:
Create a Camera class that has an x position, y position, width and height. When you update to scroll the screen (Whatever way it may be scrolling) simply add or subtract the coordinates of the camera. During this time, update the objects on the screen by setting there position with a camera offset. It could look ...
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 ...
0
I assume you're using C#. Even if you're using Java your problem lies here:
public static Sprite[] grass = new Sprite[7];
for(int i=0; i<grass.length;i++){
grass[i] = new Sprite(16,0,i,SpriteSheet.tiles);
}
This for() loop is outside any function, and as such not acceptable.
You can't initialize array members that way for static members (or any ...
1
You need to create polygons to check for collisions and check them every step in updating the position. I found example in the internet and try translate comments to English.
You can download example.
Other way is creating collision map, like this
P.S. Sorry for Google-translate.
0
If you developed the demo in the video on your own you should be able to understand what is needed for the movement animations. You need to post examples of attempts at coding the movement.
In simple terms;
You need to capture the movement event(s), you then need to specify which animation(s) to use in those events.
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
Yes it would be inefficient. However it's up to you to decide if it is too inefficient. It depends on how often you would be calling LWJGL.
See http://stackoverflow.com/questions/7699020/what-makes-jni-calls-slow and http://192.9.162.55/docs/books/performance/1st_edition/html/JPNativeCode.fm.html. Chapter 9.2 Examining JNI Costs from the second link ...
0
If you are very new to all of this I strongly recommend using Greenfoot, it is an environment for learning Java by making games. They have many tutorials and will ease you into Java and Game development.
http://www.greenfoot.org/door
1
Sometimes using a 0 or very low value for the zNear will result in a bad depth calculation.
Try using the following instead:
gluPerspective(30f, 1024f / 768f, 1.0f, 100);
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
start with Java, it's going to be A TON easier than c++. although c++ doesn't have any dependencies, java is better to start out with when creating a game like you've described.
c++ honestly wouldn't be necessary in this case
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
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 ...
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 ...
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:
...
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/
...
0
As a possible alternative, you might consider a job system. You would create jobs/commands/tasks -- essentially, bundles of information that tell you what and how to execute to e.g. do collision checking -- and schedule them for the subsequent frame. Each frame you would build the list of things you'd want to do for next frame, possibly including ...
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 ...
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 ...
0
You might want to take a look at the Lightweight Java Game Library, despite your asserted gripe with "the existing ones"
To quote the authors themselves:
LWJGL is primarily an enabling technology which allows developers to get
at resources that are simply otherwise unavailable or poorly
implemented on the existing Java platform
As for your ...
0
Have you tried like ANY opengl tutorial? Most of them are using WinAPI to create the window and pretty much describe everything you need. Probably the most famous one being that by NeHe: http://nehe.gamedev.net/tutorial/lessons_01__05/22004/ but there are many more on the net.
0
Bug #1:
You are passing the x-position of the player-character (at this point at least 700) to the Enemy.move method. In that method you subtract the argument from the x-position of the enemy (player position + 200). That means on the first frame, the enemy position will be reduced to about 200, and on the next frame into negative.
You likely want to ...
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 ...
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 ...
0
Assuming your tiles / enemies / items all share a common base class, I don't see why this wouldn't work with a 1 dimensional array. You simply call each element as normal, except now you lose the ability to reference a tile by it's position easily. However, you can still do this pretty easily with the xyz components you mentioned.
If they do not have a ...
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 ...
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 ...
1
This answers the main question: "So my question really is how would I be able to stick OpenGL (I would like OpenAL and maybe OpenCL too) in a single jar and nothing else?"
You may choose to place all the JogAmp JOGL 2.0 JARs inside your main JAR when you export your application using Eclipse.
Use the "Package required libraries into generated JAR" in the ...
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 ...
0
path="/res/particles/file.xml";
emitter = ParticleIO.loadEmitter(path);
This fixed the problem thanks to Cristina
1
One option is having a vertex buffer describing the positions of the object's vertices, and then using something like glBufferSubData to update those positions to move them around. That could be generalized to having a way to update any particular attributes being sent to the vertex shader (color, opacity, transformation data, etc.).
So you'd create a ...
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).
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 ...
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 ...
5
You aren't resetting the modelview matrix, so each cube's translation is added to all further cubes. Use glPushMatrix and glPopMatrix around each translate-and-call.
0
If you'll keep the Pixmap object you'll be able to check for the alpha component in the relative location.
Try the following code:
final Pixmap pixmap = new Pixmap(Gdx.files.internal("brush"));
Image brushImg = new Image(pixmap);
brushImg.width = mStage.width()*0.75f;
brushImg.height = mStage.height()*0.75f;
brushImg.setClickListener(new ClickListener() {
...
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).
...
Top 50 recent answers are included


