Tag Info

Hot answers tagged

11

One way to do this is to check the bounding box of the block against the bounding box of the current view (plus a bit for safety). If the block interacts with the view (either fully inside or clipped) then draw it. If it doesn't - i.e. is totally outside then don't draw. This check can be performed quite quickly - particularly in 2D. You don't have to know ...


9

You'll want to get a vector based on your current velocity and heading. Then use that vector to increment your position. //first get the direction the entity is pointed direction.x = (float) Math.cos(Math.toRadians(rotation)); direction.y = (float) Math.sin(Math.toRadians(rotation)); if (direction.length() > 0) { direction = direction.normalise(); } ...


7

My opinion is that an entity should have its own Update method, but not its own Render method. The entity contains most of the information necessary to update itself. It may require a bit of information about the context, such as the world, other entities nearby, etc., but most of the information is contained within the entity. Therefore it is the natural ...


6

Targeting/Attacking - That's fine. There are optimizations here, but don't worry about those yet. 2D Camera - No, that's not the way you do a camera. I'm sure your engine must have a camera class built in. If not, Slick2D has the option to translate. So before drawing your scene, you translate the scene by the 2D camera offset. Then draw your entities at ...


6

setShowFPS(false) from GameContainer. Use google (great tool trust me) and RTFM. Do you make a bit of research before asking here, you could save a lot time by simply typing slick2d hide fps in google. Please accept the answers you got.


6

What that code is doing is limiting motion to only if you're inside the screen. What you should instead do is something like this: //control code here if(player.getx() > 1024){ player.setx(1024); }else if(player.getx() < 0){ player.setx(0); } that way if the player exceeds the bounds of the screen the position will be set back to the ...


6

So my solution for this is that i created a SAVE class that stores all variabiles that i need public class Save implements java.io.Serializable{ Person person = null; int gold = 0; Job currentJob = null; Job currentWifeJob = null; Wife currentWife = null; Food currentFood = null; String currentCity = null; ...


5

You can't. The nature of any kind of digital data is that once information has been removed it can never be put back, and likewise you can't fill in information that was never there in the first place - the best you can do is a rough approximation, which gives you blurriness. Using GL_NEAREST won't blur but it will become pixellated instead. The solution ...


5

Adding an artificial delay is a really bad idea IMHO. 1) It's unexpected - what other well-known platformer does it that way? 2) It limits your player's jumping accuracy, because in tight situations, it might prove fatal (the character falls off a platform because you can't take off quickly enough), which would be the ultimate turn-off for any player - ...


5

Not really, no. There's one scenario: you're calling the draw method so often you don't leave yourself the resources to do anything else. That's not your FPS negatively affecting how the game runs, though. The cause would be a badly written game, engine or framework; the FPS would just be a side-effect. You have a glitch that surfaces on your desktop. Your ...


5

rate * time = distance Establish a rate of movement in whatever units of measure you want (such as pixels per millisecond). Get the time since the last update that has passed (elapsed time). Establish the direction of movement (you're already doing that).


5

There is a mismatch with the objects you write (currentPerson thru year, 14 objects) and those you read back (currentPerson thru generationList, 9 objects). And once you've completed a player, you need to reset i to zero. You can break the loop, when the object is null.


4

There is no "best overall". This is where the prohibition about premature optimization comes from; neither method is likely going to impact your performance in any measurable way. Personally, I wouldn't make buildings tiles at all; they should be sprites. Technically, they are a modified form of unit. This allows them to act like units in meaningful ways. ...


4

You have to cast the GameContainer object, that is passed in the update method into AppGameContainer, then you can access setDisplayMode... I tested it right now, and it works. AppGameContainer gc = (AppGameContainer) container; gc.setDisplayMode(800, 600, false); But I think you need to use the dev branch of slick, as the "official" version from their ...


4

Error stacks go from the most recent call to the least recent, so the most recent line is what happened, and all the rest are what it happened within, what method that was called from, what method that was called from, and so on. Wed Jun 13 21:03:58 ADT 2012 ERROR:For input string: ",B6,W5,B2,W7,B,B,W,W" java.lang.NumberFormatException: For input string: ...


4

I'm not sure this kind of functionality is engine-specific. If you have a way of setting a global alpha, then you could do it just fine. Interpolate the scene alpha and the menu alpha through time, for example, for one second... timeStarted = currentTime() //Time in milliseconds since the program started, probably 0 if this is the actual start of the ...


4

First of all, don't listen to people who say that Java is a bad language for making games in. Everybody should start their game development career by using the tools you're already familiar with. It seems your animations are entangled with your images, which makes it difficult to share animations between objects. I propose that your animations should not ...


4

At one place in your code, you create your game container. If you followed the tutorials, that part will look something like this: AppGameContainer container = new AppGameContainer(game); Now you can call setDisplayMode on the container object: container.setDisplayMode(640, 480, true); The first two parameter define the window resolution, the third if ...


4

If you're using Slick2D to create the rectangle. Slick2D has a Shape class that can be used to describe such things (rectangles, circles, etc.). I imagine you're using a shape like this for collision because it has methods like intersect()(link) that allow you to detect such things. Shape also has a nice method called transform()(link). It can be used to ...


4

pseudo-code: ClearAllCells(); foreach(entity) int minXCoord = floor(entity->GetPosition().x-entity->GetRadius()) / CollisionGrid.CELL_SIZE; int minYCoord = floor(entity->GetPosition().y-entity->GetRadius()) / CollisionGrid.CELL_SIZE; int maxXCoord = ceil(entity->GetPosition().x+entity->GetRadius()) / CollisionGrid.CELL_SIZE; int ...


4

I'm not sure how you're not seeing this problem in the debug version. for (Particle o: particleList) { if(o.emitter.completed() == true){ particleList.remove(o); } Attempting to remove an item from a list while iterating through that list will give you a concurrency exception. Instead of particleList.remove(o); add the item to remove ...


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).


3

You're in luck. In Slick2D, Image has a function called getGraphics, which will return you a Slick2D graphics context. While the graphics context does not have a setPixel function, it does have a fillRect function that you can use to set a single pixel. Graphics g = img.getGraphics(); g.setColor(color); g.fillRect(x,y,1,1); g.flush();//IMPORTANT!!! I ...


3

I recently had the same sort of issues. I recommend the following: First, get jarsplice. Also, assuming that your dev environment is Eclipse, but if not, you'll need to do the equivalent. Export your game to a jar (NOT a runnable jar, just a regular jar) Start jarsplice. Add your jar. Add slick.jar, lwjgl.jar, and whatever other jars you are using from ...


3

I'm not too familiar with Slick2D, but assuming it's sending back uncompressed data like most other methods of this type are, the byte array just represents color channel data packed together. Each color consists of a Red, Green, Blue, and sometimes Alpha channel. Typically the order of these channels are RGBA, but it's possible that the orders are flipped, ...


3

The standard approaches are (pick one): Increase your boundary width AND/OR reduce the maximum speed of your bullet so that it can never jump through a wall in a single update (requiers a bit of Pythagoras to figure out the maxium distances / minimum boundary widths); Perform continuous collision detection (CCD), usually by raycasting to detect collision ...


3

You can do this by using the dot product of the velocity of your player. First, you need to store your player's velocity and use it to update his position. Then, for each trigger in your level you will test if the user is moving towards the center of the trigger (using the dot product between the velocity and the trigger): Sprite { Point position; ...


3

Normally the main compatibility issues are between major versions. If you compile for Java 6, it will not run on Java 5 but throw an java.lang.UnsupportedClassVersionError. So a program complied on Java 6 Update 24 is supposed to work on lower versions of Java 6. But there is a small risk that you invoke a method that was added in a minor release, resulting ...


3

From the documentation you linked, here are the different implementions you will have to use based on the functionality you desire: NiftyGame, NiftyBasicGame - Implementing the Game or the BasicGame, this classes are supposed to display only the Nifty-GUI over the entire game. NiftyGameState, NiftyBasicGameState - Implementing the GameState or the ...


3

The easiest way to handle this is to use a library that's specifically designed for GUIs. Check out Nifty GUI. It works with OpenGL + LWJGL + Slick. Follow the getting started guide and read the tutorials. Finally, check out the source code for the examples. This will get you on your way the quickest, without needing to worry so much about the lower level ...



Only top voted, non community-wiki answers of a minimum length are eligible