Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Bitmaps: What are they?  (Read 1188 times)
0 Members and 1 Guest are viewing this topic.
Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Posted 2011-12-14 23:45:22 »

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
1  
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? Cry

Thanks!

Check out my website!
Offline sproingie

JGO Kernel


Medals: 202



« Reply #1 - Posted 2011-12-15 01:30:28 »

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.

Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #2 - Posted 2011-12-15 01:47:52 »

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

Check out my website!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CyanPrime
« Reply #3 - Posted 2011-12-15 01:49:10 »

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

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #4 - Posted 2011-12-15 01:59:02 »

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

Check out my website!
Offline sproingie

JGO Kernel


Medals: 202



« Reply #5 - Posted 2011-12-15 02:11:34 »

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

Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #6 - Posted 2011-12-15 03:59:46 »

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

Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #7 - Posted 2011-12-15 04:34:40 »

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

Check out my website!
Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #8 - Posted 2011-12-15 05:00:40 »

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 Smiley

Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #9 - Posted 2011-12-15 14:21:31 »

Thanks! Smiley

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?

Check out my website!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #10 - Posted 2011-12-15 17:50:19 »

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

1  
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.
Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #11 - Posted 2011-12-15 21:47:11 »

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
public void update(long deltaTime) {
    double dt = deltaTime/1000.0;
   
    speed += accelPerSecond * dt;
   
    x += speed * dt;
   
    ...
}

Offline h3ckboy

JGO Coder


Medals: 5



« Reply #12 - Posted 2011-12-19 17:01:26 »

wouldnt it already be in nanoseconds?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (64 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (42 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!