Can anyone give me a code snippet or link to something like this? I am just starting out with Java game development and I have been repeatedly frustrated to find that most of the tutorials out there will not work with java1.5. Anything I can find about displaying an image is either in an applet, or wont work with 1.5

All the good tutorials I have found by searching this forum, like the Space Invaders101, or the Cursos de Tutoriales invaders page no longer work.

All my java books from my classes are the same way, they only use applets or are too old to be usefull with 1.5.

//Called by the model (the class controlling the entire game) every timesteppublicvoidupdate() {repaint(); }

//By overriding this method, you can add in your own things to drawpublicvoidpaintComponent(Graphicsg) {//Call the super method so that the screen is refreshedsuper.paintComponent(g);//Draw the image, but make sure it is loaded all the way firstif (pic.getImageLoadStatus() == MediaTracker.COMPLETE)g.drawImage(pic.getImage(), xPos, yPos, width, height, pic.getImageObserver()); }}

And that will work, as long as you have your own values for xPos, yPos, width, height. If you don't understand something, let me know.

Basically, repaint() tells a JComponent to redraw everything to its new positions. This calls the screenUpdate (?) method (which you don't need to worry about) to erase the screen, then calls paintComponent to draw the background and foreground, etc. If you override this method, you can add in things to draw.

You look like someone who hasnt even learned the basics (yes, the syntax is wrong... your syntax actually [see the other thread])... and despise that kev wrote a perfectly fine reply... and you call that "nasty". No one gets you. Really.

Thanks for all the help guys. Especially you oNyx, your reply was so full of constructive criticism, it gave me new hope. It really helped me a lot. I would also like to thank Kev for all the helpfull suggestions he made. They really helped a lot too! I can't wait to try some of the things you guys have suggested.

Y'know everyone gets frustrated occasionally, but there is no reason vent your anger on others. And those who try to help you (and actually do help you - even if you dont realise that) are really a bad choice for that. Dont you see how silly that is?

Yeah, no problem with the help, but definitely don't be angry if you don't get any. Sometimes people don't have time. This forum works better if you ask advice and then give advice back when you can, as positively as possible. The only reason Kev didn't give such a detailed reply was probably because he wasn't getting bored in Assembly class like me.

A BufferedImage is much more complicated but allows for many more things to be done to the image, such as tinting or cutting out pieces of an image. ImageIcon is only a simple image that cannot be seriously altered – the only real things you can change are how it is drawn with g.drawImage(). If you are simply using sprites, ImageIcon is certainly the way to go because it is simpler (aside from the fact that this forum is for newbies), but if you are doing more complicated procedures like multi-layering an image or mapping to 3D textures, you definitely do not want to use ImageIcon.

For a 2D sprite-based game, however, it's (in my opinion) always the way to go.

Yes, an ImageIcon is not a real image, but something containing an image. Therefore the rendering probably depends a lot on the properties of the internally stored image, which could easily be a BufferedImage or some other type.

Oh yeah, good calls, I forgot about this because I've typed it so much I don't even think about it.

When drawing an image icon, you need to say imageIcon.getImage(), because it needs to pull the actual instance of Image out. Doesn't ImageIcon itself actually extend Object only? It has its own paintIcon method as well, but I find doing it with drawImages gives more options.

One thing I did always like was that ImageIcon's also have their own ImageObserver, which simplifies having to worry about that.

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