Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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  
  Game programming questions  (Read 2481 times)
0 Members and 1 Guest are viewing this topic.
Offline svartberg

Senior Newbie

« Posted 2007-01-11 22:11:49 »

Hello there. I have made a 2d maze game recently like pacman. Im going to develop a 2d fighting game now. In my maze game i used the ImageIcon to present an image, now i wanna try the Image object instead.

I have some questions before i start to to this. I have read the great tutorial at
but still i don't understand everything. Here are my questions.

1. How do I paint some part of a big picture like a image file containing all the sprites I wanna use?

2. How does the paint() method work? I mean does the image disappear that i painted when I paint another one or can i clear the previous one and restore the background there?

3. Is the rectangle intersects technique good for collision detection between object,? or is there a better technique cause im going to do a fighting game and the pictures wont be rectangular.

Thanks // svartberg, new started game programmer.
Offline svartberg

Senior Newbie

« Reply #1 - Posted 2007-01-13 21:20:05 »

okay the first question i found the answer for, cause there is a graphics.drawImage method that paint some part of a picture to the screen.

my next question i haven't find any answer for. I know there is a repaint() method that paint the component, but does it have to paint all images like the background also, or just a specific image?

and about the third question i found out that maybe the collision detecting will work out fine, with points but im not sure how it work, I'll give it a try i guess.

Please give me suggestions and tell me how the painting works. // svartberg
Offline BloodRain

Junior Devvie

« Reply #2 - Posted 2007-01-13 22:36:33 »

You can try pixel perfect collision or you can use a bounding polygon .
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nazrol

Innocent Bystander

« Reply #3 - Posted 2007-01-14 12:55:30 »

yes, it exist the draw method in java.. and you also can use repaint to update your graphics.. that you want update for example for every 1000 ms = 1 s.I'm also new to java game developpement.. but if you understand how to use timers, thing would become more easy for you. For example, the method paint, you place all the elements that you wish to draw and you create a global timer which calls the method repaint() every 1000/FPS (FPS = 80). This will redraw all the elements in paint().. and to control the other objects you can create another timer for example to move a block to the right every 2 s by 10 pixels.. you just add the current position in your new timer.So there are two timers, one that calls repaint() every 1000/FPS and the other one that adds the current x position.Also you can use the buffering, but as for beginner like me, i just use this style of coding in my first java game, tetris... hope this msg is useful to you
Offline rdcarvallo

Senior Devvie

Projects: 5
Exp: 15 years

2D Java games forever!

« Reply #4 - Posted 2007-01-15 16:17:15 »

About your second question:

The method repaint() asks for the scren to repaint, that is done by awt calling to the update(Graphics) method

The default update(Graphics) method clears the screen and calls to paint(Graphics), that's why in the paint(Graphics) method you draw all of your image again.

You can override the method to use some kind of double buffering and avoid flicker.

Next about painting, each time you draw a image in the graphics object you change the pixels so you cannot delete a image to restore the backgorund. If you need to repaint the backgorund you ned to draw the image again.  (But this is covered by the update() -> paint() cycle)

Hope this helps,

Offline JAW

Senior Devvie

Medals: 2

« Reply #5 - Posted 2007-01-15 21:37:51 »

I do recommend getting a book like. There are 2 or more Java Game Programming Books on Amazon. If you can afford it, they definetely cover some questions you have now and will have later.
Try Java 2 Game Programming by Thomas Petchel
Its more basic.

Offline fletchergames

Senior Devvie

« Reply #6 - Posted 2007-01-15 22:01:03 »

Try Killer Java Game Programming or Developing Games in Java.  You can sometimes pick up programming books for only a couple bucks plus shipping on  I haven't read the book JAW mentioned, so I can't comment upon it.

Don't try Advanced Java Game Programming or Black Art of Java Game Programming.  In general, don't try any programming book more than 2 years old unless there's no newer one available or it's a mature technology that hasn't changed much (e.g. sorting algorithms).  Developing Games in Java is an exception, but Killer Java Game Programming is better anyways.  I have both, and they each have some (not alot) of material that the other doesn't cover.
Pages: [1]
  ignore  |  Print  

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

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

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

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

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

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

Solater (98 views)
2018-03-17 05:04:08

nelsongames (179 views)
2018-03-05 17:56:34

Gornova (405 views)
2018-03-02 22:15:33

buddyBro (1065 views)
2018-02-28 16:59:18
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!