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

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


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

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


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


4

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


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

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

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


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


3

You can add a little timer: if(gc.getInput().isKeyDown(Input.KEY_SPACE) && gameTime.getTimeMS() - shootTime > shootDelayInMilliseconds) { shootTime = gameTime.getTimeMS(); bullets.add(new Bullet(player.getPos().getX() + 30,player.getPos().getY() + 17)); } Basically you are noting the last time your character shot, then ensuring that ...


3

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


3

I have elaborated on my comment suggestion, but the answer to your questions are: Yes, there are alternatives to a singleton. I present one shortly. Whether you want to serialize your information to xml, a database, yaml, or whatever is up to you. I do not recommend serializing to your chosen method each time your character drinks a potion or whatever, ...


3

glBindTexture is the only option for changing textures in OpenGL, but there are a few things you can do to make things easier on yourself. First of all you can wrap it with your own version. That just takes a texture number, compares it to the current texture (which you'll declare as a variable), and if it's changed calls glBindTexture and stores the ...


3

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


3

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


3

Well the question really is how do you compile your game: If you just use javac in the console, make a batch file (in whatever batching language your OS supports, i.e. .bat file for windows, .sh file for Linux, etc) that before executing the compiling command (or after) will read the current build number from a text file, increment it and re-write it; If ...


3

Just make a global field that records the damage to be dealt (the value obtained when pressing one), then when you press left, before decrementing the life, deduct the amount to decrement it with from the damage to be dealt value and check if that damage to be dealt value is still positive. When it becomes negative that means you've dealt enough damage and ...



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