Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2
1  Game Development / Newbie & Debugging Questions / Re: 2D Timing Mechanism on: 2008-09-24 13:33:32
Yeah, it appears that Windows 98 is the one with timing issues and I really don't care much about supporting it.

2  Game Development / Newbie & Debugging Questions / Re: 2D Timing Mechanism on: 2008-09-24 01:40:29
That's exactly what I was looking for.  It appears it hasn't changed much.  With Java 1.5+ is System.nanoTime a better choice for timer resolution than System.currentTimeMillis?  Or does currentTimeMillis try to use the highest resolution timer available in more modern VMs?

3  Game Development / Newbie & Debugging Questions / 2D Timing Mechanism on: 2008-09-23 03:13:43
I've seen a lot of tutorials on how to do 2D games.  I've done a couple myself, but really haven't dug into it since Java 1.4 was in beta.  Back then, the easiest thing to do to control a smooth framerate was a hack that involved an auto-adjusting thread that would sleep 1ms and "tick" every X milliseconds (where  was 1000/frame rate).

If I was to start creating a 2D game with the core libraries, what would be the "latest and greatest" strategy to maintain a frame rate and draw to the screen?  BufferStrategy and fullscreen?  Another sleep/notify thread?  I've seen a few, but I'm looking for the best to start with (and possibly an example) with the 1.6 library.

Thanks for any guidance or links you can propose!

4  Java Game APIs & Engines / Java 2D / Re: Still having trouble with 90-degree turns... on: 2004-01-30 16:00:02
Oh, I think the other topic on mirroring an image confused me.  I was under the impression you could get 90-degree rotation, but I guess it's only 180.  Still, two sets of sprites is better than four!


Michael Bishop
5  Java Game APIs & Engines / Java 2D / Still having trouble with 90-degree turns... on: 2004-01-29 22:40:17
I've managed to do a 180 degree flip using drawImage() but I can't seem to get 90 degrees.  If I draw a single Pacman with his mouth pointing, say left, can't I use drawImage() to render that image with him pointing up, down, and right?  Given that the sprite is 32x32:

drawImage(img, 0, 0, 32, 32, 32, 32, 0, 0, null) should turn a left-facing Pacman to a right-facing Pacman.  I can't figure out how to get an up/down facing Pacman, or is this not possible and the image is only flipped?

Michael Bishop
6  Java Game APIs & Engines / Java 2D / Re: Mirroring an image on: 2004-01-23 13:08:34
OK, so to sum up for best performance and efficiency:

Let's start with Pacman (since I'm working on it and it's a situation everyone should be familiar with).  Pacman himself has nine frames of animation.  I have all 9 of these frames in a PNG file that are loaded as compatible images.  That should be all I need because with the drawImage() function, I can "flip" him 90 degrees in any direction and still retain hardware-acceleration.

Then we move to maze tiles.  All the unique ones are stored on the hard drive as PNG files and again are loaded as compatible images.  Again, they can be turned 90 degrees with drawImage().  The difference here is that some mazes are different colors.  So in the "pause" between loading levels, I can use the Java2D API to do a color-swap and store the new images in memory.

For ghosts, it's trickier because they never flip 90 degrees; the only thing that moves are their eyes.  Regardless, I have one strip of ghost animations.  At load-time for the game, I take that strip, convert it into 4 different colors and associate each set of images to each ghost.  It would be too expensive to swap colors and draw as necessary each frame, but that saves me from having 4 times as many ghosts stored on the hard drive.

Does this cover it, or am I missing something else?  The gist of it is that color-swapping is done at load time; I will always have images of different color in memory.  Rotation, or more specific, 90-degree turns do NOT need to be stored in memory because the particular flavor of drawImage retains hardware-acceleration unlike something like an AffineTransform.  Correct?

Michael Bishop
7  Java Game APIs & Engines / Java 2D / Re: Mirroring an image on: 2004-01-21 21:24:41
As far as changing a single color, here's what I came up with:

public BufferedImage changeColor(BufferedImage inImage, Color oldColor,
                  Color newColor) {
            // Get the width and the height of the image we're going to change.
            int imageHeight = inImage.getHeight();
            int imageWidth = inImage.getWidth();
            // Get the old color we want to change in the integer (ARGB) form.
            int targetColor = oldColor.getRGB();
            // Create a single-dimension array that has enough room to hold all
            // the pixels of the changing image.
            int[] imagePixels = new int[imageWidth * imageHeight];

            // A PixelGrabber simply populates the above array with all the ARGB
            // values of the image we want to change.
            PixelGrabber pixelGrabber = new PixelGrabber(inImage, 0, 0,
                        imageWidth, imageHeight, imagePixels, 0, imageWidth);
            try {
            catch (InterruptedException iE) {
                  return inImage;
            // Make sure no errors occured.  If they do, just give back the
            // original image.
            if ((pixelGrabber.getStatus() & ImageObserver.ERROR) != 0) {
                  System.err.println("Pixel-grabbing aborted or errored.");
                  return inImage;
            // Create another array.  This array will be another array of pixels,
            // but is intended to store the changed values.
            int[] newPixels = new int[imageHeight * imageWidth];
            // Create an Image made from a MemoryImageSource.  As we change the
            // values of the pixels, the resultant MemoryImageSource will change
            // thus the Image will change as well.
            Image newImage = thisToolkit.createImage(new MemoryImageSource(
                        imageWidth, imageHeight, ColorModel.getRGBdefault(),
                        newPixels, 0, imageWidth));
            // Iterate through our ENTIRE set of old pixels.
            for (int y = 0; y < imageHeight; y++) {
                  for (int x = 0; x < imageWidth; x++) {
                        // Get the current pixel value and compare it against the value
                        // of the color we want to change.  If they're not the same,
                        // don't change the original value.
                        int currentPixel = imagePixels[x + y * imageWidth];
                        if (currentPixel != targetColor) {
                              newPixels[x + y * imageWidth] = currentPixel;
                        // Otherwise, change the value to the NEW color value.
                        else {
                              newPixels[x + y * imageWidth] = newColor.getRGB();
            // Flushing the Image in this case flushes any buffered pixel data to
            // ensure all our changes have been applied to the Image.
            if (newImage != null) {
            // Now we want an Image to return to the user.  Of course we want it
            // to be a candidate for hardware-acceleration, so we use another
            // method of this class to ensure that.
            BufferedImage returnImage = createImage(imageWidth, imageHeight,
            // Draw the new Image to our returnImage and, well, return it!
            Graphics2D returnGraphics = returnImage.createGraphics();
            returnGraphics.drawImage(newImage, 0, 0, imageWidth, imageHeight,
                        0, 0, imageWidth, imageHeight, null);
            return returnImage;

Pretty self-explanatory; the createImage() call is a call to GraphicsConfiguration.createImage() and thisToolkit is a Toolkit.  The only problem is that when you render your original image with anti-aliasing, you get different shades of a particular color.  I need to modify that function to determine whether or not a color is a "shade" of the given color and apply the same shade of the new color.  Aside from that, it works well.  Thanks Onyx!

Michael Bishop
8  Java Game APIs & Engines / Java 2D / Re: Mirroring an image on: 2004-01-20 22:37:23
That's interesting, but the concept of working with MemoryImageSource and PixelGrabber is new to me.  I get the idea, but what happens if you only want to manipulate a certain color?  When ghosts are "energized" because Pacman ate a power pill, they go to blue ghosts with white faces.  When they start flashing, they alternate between the above and WHITE ghosts with BLUE faces.  Is there a way to say "Take this particular color and make it this other color"?  Your example appears to be images with different shades of the SAME color; you don't have multiple colors.

I also assume that since you're painting it to a compatible Image, the result is hardware-accelerated or at least a candidate for it.

Thanks a bunch, this is pretty helpful.

Michael Bishop
9  Java Game APIs & Engines / Java 2D / Re: Mirroring an image on: 2004-01-20 00:15:07
Well can we take this a step further?  If this guy can face left and right with drawImage(), can he also face up and down from the same original image?  The JDK docs say "scaled and flipped", but doesn't say anything about rotation.  If you want your sprite to go 4 directions, it looks like you need two source images.  One for up/down and the other for left/right.

A different question also begs palette-swapping.  In my Pacman case, a ghost is blue when you eat a power pill.  When he's getting ready to turn back to normal he flashes white.  Do I need new images for that, or can I say "Turn all the blue pixels white"?  And will it be hardware-accelerated?

Didn't mean to hijack a topic, but I figure my questions are in the same vein.

Michael Bishop
10  Java Game APIs & Engines / Java 2D / Re: Best way to load images. on: 2003-12-18 00:42:18
Yes, so many questions, but so many good answers.  Oddly enough, my current ImageManager class gave the user the ability to create a compatible Image and load an Image from a File.  I was on the right track.  Thanks a lot for the concise and solid answers to my many questions.  That pretty much nailed it for me.

Michael Bishop
11  Java Game APIs & Engines / Java 2D / Best way to load images. on: 2003-12-16 17:31:23
Hello all.  If I want to store and load images for a game, what is the best way to go about it?  I'm interested in the following:

Hardware-acceleration? (If I remember correctly, this rules out Toolkit.getImage()).

Format?  I hear PNG is the best.  I'm interested in basic, small sprites (32x32 or 64x64) with single transparency (BITMASK?)

Transparency?  Last time I tested, for some reason, TRANSLUCENT was actually better and faster than BITMASK.  This was around the release of 1.4.0.

Classpath?  Using ImageIO and Toolkit, they want a URL or a filename.  If you JAR up your entire package including images, it makes more sense to use getResourceAsStream().  I'd rather my images be found on the classpath than through absolute or relative file names.

So in essence, I'm looking for the best format to write an image in for gaming.  Afterwards, I'd like to load that image and maintain transparency, have hardware-acceleration, and be found on the classpath.

Too much to ask?  I'm hoping there's some kind of best practice.  No third-party libraries either.  I'm aware of GAGE and LWJGL, but this is a learning exercise for me and I'd like to do it using core libraries and extensions.  Some of you might remember my Pacman project over a year ago, and I'm trying to improve on that again.  The images were rendered at runtime using Arc2D and Rectangles, so I never worried about loading them before.

Thanks for any help!

Michael Bishop
12  Games Center / Archived Projects / Re: Black Tiger now with online high scores too :- on: 2003-04-23 14:47:31
Beautiful!  I love Black the PCB for my arcade cabinet at home, but it sure as hell doesn't save high scores.  No problems here, except the window was really small.  My desktop resolution is 1280x1024.

Windows XP
Java 1.4.1_01

Michael Bishop
13  Discussions / Miscellaneous Topics / Re: Anyone know where I can get a Sun T-shirt? on: 2003-04-04 18:31:02
lol, I'm a large.  I'll see what I can do about pictures.  Working at a C# shop is going to be tough getting a partner in crime to take a picture.  It's not until the end of May.  29th to be exact.  If you'll seriously send me one, great, let me know Space Ghost, otherwise, I'll get one ordered off one of these other sites.  Thanks for the posts people and yes, I'll try to get a decent picture.
14  Discussions / Miscellaneous Topics / Anyone know where I can get a Sun T-shirt? on: 2003-04-04 13:53:45
I gotta attend a Microsoft Visual Studio .NET 2003 launch event in May.
15  Java Game APIs & Engines / Java 2D / Re: GAGE Engine Early Access on: 2003-04-03 12:58:26
Pretty solid.  Sound lags a bit, but the timing and everything seems OK.

Michael Bishop
16  Discussions / Miscellaneous Topics / Re: Pick Up The Phone Booth And Die 2 on: 2003-03-26 12:40:49
To turn on the fountain, steal the cow's food...Smiley  I'll check out the Howitzer.  Haven't done a thing with the tree.  I imagine maybe you can water it or something?

Michael Bishop
17  Discussions / Miscellaneous Topics / Re: Pick Up The Phone Booth And Die 2 on: 2003-03-25 19:35:41
Now you got me curious.  I found the screwdriver, moved the Howitzer around, turned on the water fountain but...Huh

Michael Bishop
18  Discussions / Miscellaneous Topics / Re: Pick Up The Phone Booth And Die 2 on: 2003-03-24 19:08:40
I think the 2nd one is a demo and not a full version.  You can go N, S, E, W in the 2nd one, but sometimes you try to move and it says something like you can do that if it was a full version and not a demo.

Michael Bishop
19  Discussions / Miscellaneous Topics / Re: A Difficult One! on: 2003-03-14 17:01:51
Hi Toby,
    Sent you an email.  And yeah, I agree, doesn't necessarily have to be FFT, but it would be nice to model some kind of tactical RPG.  Seems to be a successful genre lately.

Michael Bishop
20  Discussions / Miscellaneous Topics / Re: A Difficult One! on: 2003-03-13 18:47:26
Wow, sign me up for the FFT team.  I'm having my first playthrough (spread out over several months) and it's pretty fun.  Just started Chapter 4.

Favorite console game: Judging solely by time spent, I'd have to go with the Hot Shots Golf series for PS/PS2.

Favorite PC game: I'd say the old Sierra adventure game series.  Played a lot of King's Quest and Space Quest games to single one out.

I love RPGs, but I rarely play them more than once.

Michael Bishop
21  Discussions / Miscellaneous Topics / Re: First post! on: 2003-02-28 14:07:16
Ah, chalk me up for Blade Runner as well.

Michael Bishop
22  Games Center / Archived Projects / Re: Platform game (not finished) on: 2003-02-21 15:36:43
I used the SleepTimer in my Pacman demo.  Look at the class at

The run() method is where it's initialized and used.

Michael Bishop
23  Games Center / Archived Projects / Re: Platform game (not finished) on: 2003-02-10 16:27:48
Wow, that was pretty decent.  My only complaint is that it ran TOO fast, but I'm definitely impressed.

Michael Bishop
24  Java Game APIs & Engines / Java 2D / Re: Page Flipping on: 2003-01-17 14:25:06
For what it's worth, the Gameboy Advance is an LCD screen system, yet the code to draw to the screen is still vblank-based.

Michael Bishop
25  Games Center / Archived Projects / Re: New World Order: The Fortress on: 2002-12-10 11:59:47
It ran pretty good under Windows XP for me.  Really didn't look like there was any gravity or clipping, but the guy animated smoothly and the screen scrolled just fine.  I was getting around 55FPS.  I have a P3-733 with 512MB RAM, onboard video, and an ATI XPert 128 (Dual monitors).  It's a work computer, so nothing's gaming material.  I did notice that when it ran in fullscreen on my primary monitor, it moved all my other windows to the secondary monitor.  Strange.

Michael Bishop
26  Game Development / Shared Code / Re: Sleep based timer hack on: 2002-11-06 12:00:49
That sounds suspiciously like garbage collection without seeing any code.  Definitely avoid creating objects in your render loop and run it against a profiler.

Michael Bishop
27  Java Game APIs & Engines / Java 2D / Re: Tricks to get smooth animation on: 2002-11-04 13:43:12
Actually, in the Pacman example, I found that redrawing the screen was necessary.  setClip() and dirty rectangles breaks a more important commandment; creating objects.  setClip() creates a new rectangle object every time you call it and causes the code to slow down.

To avoid recreating images as much as I could, I used a couple layers:

- The maze (never changes)
- The pills (same size as the maze, like an overlay.  Obviously, this one changes when you eat a pill)
- The sprites (Don't change, but they move)

    Of course, the possibility exists that I could've used setClip() wrong and maybe there's better performance to be had, but with what I've done, it didn't turn out well and I discovered the Rectangles being created in a profiler.

Michael Bishop
28  Game Development / Shared Code / Re: Sleep based timer hack on: 2002-11-01 11:57:02
This is all the code I used to get it running at "fps" fps.

frameTimer = new SleepTimer();
frameTimer.setDelay(1000 / fps);
frameTimer.setAutoCorrection(true, fps);

I've never had it throw an error before.  Then again, I haven't run it over 60 frames-per-second.

Michael Bishop
29  Game Development / Shared Code / Re: Sleep based timer hack on: 2002-10-26 00:05:53
Thanks for digging it out and posting it.  I was a bit leery about doing it myself, but he did post it and I did give him credit in the code... Smiley

Michael Bishop
30  Java Game APIs & Engines / Java 2D / Re: Simple game framework? on: 2002-10-24 12:11:08
1.  The history of that particular Pacman application is that it was simply my attempt at learning Java Game Programming.  I'm the author, although the input from this community has been tremendous.  In the archives, there are an excessive number of posts.  If you're asking about the author of the class that handles timing, that would be "thelorax", another user on this board.

2.  Frames and ticks are supposed to be one and the same but it doesn't always happen.  I'll explain.

- Frames are the number of frames the application has actually drawn.

- Ticks are the number of frames the application is supposed to have drawn.  When it's time to draw a frame. the timer class "ticks" and increments its tick count.  The application waits for the next tick to maintain the given frame rate.

- When the application is ready to draw the next frame, it examines the frame count versus the tick count.  Due to garbage collection or otherwise, sometimes a frame or two is skipped.  To compensate for that, I'll do the logic loop until it's caught up again.

Take a good look at the run() method in the GameBoard class.  It does something like this:

- Run the game logic (tickCount - frameCount) times.
- Draw the offscreen buffer.
- Wait for the next tick.
- Draw the screen.

Michael Bishop
Pages: [1] 2
EgonOlsen (58 views)
2018-06-10 19:43:48

EgonOlsen (40 views)
2018-06-10 19:43:44

EgonOlsen (60 views)
2018-06-10 19:43:20

DesertCoockie (225 views)
2018-05-13 18:23:11

nelsongames (141 views)
2018-04-24 18:15:36

nelsongames (140 views)
2018-04-24 18:14:32

ivj94 (882 views)
2018-03-24 14:47:39

ivj94 (143 views)
2018-03-24 14:46:31

ivj94 (794 views)
2018-03-24 14:43:53

Solater (158 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!