Bitmaps: What are they?

What is a bitmap and how does it work? Instead of drawing really crappy backgrounds in paint, I want to just make little images and link them using bitmaps (or however it works).

Also, on an unrelated note, using this code

ImageIcon i = new ImageIcon(getClass().getResource("/textures/enemy.png"));

to load an image works fine when I run in eclipse, but throws a nullpointerexception in a jar file. Why? :’(

Thanks!

A bitmap is just a generic term for a raw kind of image format where pixel data is written out without any particular compression technique. If you’re talking about putting several images into one texture, the term you’re looking for is “texture atlas”.

As for your resource loading problem, you need to have a /textures folder at the root of your jar. If you’re using an applet, use getResourceAsStream, since the URL returned by getResource won’t be allowed to open the jar file your applet is running in. In general, prefer getResourceAsStream to getResource wherever you can.

So if I want to use a texture atlas to make a platformer, how would I do this?

If you’re making a platformer (2D) use Slick2d instead of LWJGL.

I haven’t been using either! Lol. Can you link me to this and also explain how to use a texture atlas in slick2d?

The appropriate class in Slick2d is SpriteSheet, but I think you may want to peruse the starter documentation, starting at http://slick.cokeandcode.com/wiki/doku.php

Guys, he’s using Java2D…

@Sproingie
URL works fine for files inside jars too, it’s URI that you should be worried about. :wink:

@OP
Make sure there is a “textures” folder inside the jar and the image is inside that folder

Ra4king…

Here’s a .zip with the jar and project file with source and everything. Would you mind taking a look at it? Or anyone else too.

Thanks.

Edit- forgot link >.<

http://www.mediafire.com/?3aylbsy4j2dpfwb

Try making sure you are using the correct capitalization, Enemy.png is not enemy.png :wink:

Why it works in Eclipse is because Windows is case-insensitive so it finds the file. However, Java is case-sensitive when looking for files inside a zipped folder.

In general, it’s better to use the correct case everywhere. I renamed Enemy.png to enemy.png and the jar worked :slight_smile:

Thanks! :slight_smile:

So I tried the game out on my laptop and the FPS dips to 65. Is there a way I can adjust the speed of the enemies and the players movement based on the FPS?

yeah, its rather simple, basically just keep track of how much time each cycle is taking in a variable, lets say delta. to keep track of time use System.CurrentTimeMillis() (although I will probably get attacked now about the timing not being proper or something :stuck_out_tongue: ).

then give this variable to the updating method of your entities, and have them move accordingly, for example (this is purely an example, haven’t even looked at your code)


enemyx = enemyx + movement*delta

of course you may want to divide delta by ten or something, but that depends on how fast you want things.

hope I helped.

To elaborate more on h3ckboy, you should pass a deltaTime to your update methods that indicates the number of milliseconds (or nanoseconds) since the last frame.
Then you divide “deltaTime” by the resolution (number per second, 1000 for milliseconds, 1 billion for nanoseconds) and multiply with your “speed”. However, this time you have to make sure “speed” and “acceleration” store the number of pixels you want to move per second, not per frame :wink:


public void update(long deltaTime) {
    double dt = deltaTime/1000.0;
    
    speed += accelPerSecond * dt;
    
    x += speed * dt;
    
    ...
}

wouldnt it already be in nanoseconds?