   Does my loop need to be synchronized and also a question about  double buffering
  Hello. I made a snake game the other day in Java, and although i've made anagram games and memory games, i would describe this as my first proper game. The first with a game loop anyway.I use a javax.swing.Timer to call the loop method over and over at intervals the user chooses (as they decide the speed of the snake). I have only just learned about threads and i was wondering  should I make my loop() method sychronized? If I don't is there a danger that the Timer could fire another ActionEvent before the last loop has finished running? (which would cause problems) At the moment it's synchronized but i'm not sure if that is just pointless. The other question is about should I use a double buffer. I have only just started learning about double buffering and am yet to do it in a program. And i understand it draws onto an object and not until it has finished does it draw the whole thing at once to the screen to prevent flickering.But with my code as it only calls repaint once per loop (when the snake has moved) wouldn't it be impossible for it to dislay half drawn anyway?The game works great with no flicker but obviously it's simple and my computer is fast so i'm not sure if that is just covering for what could be bad programming.Anyway any help would be greatly appreciated. How do people around here feel about people posting the code for a whole program? As I've never had any real feedback about my code it would be hugely benificial to get criticism, but i also undersand it would be time consuming for the people and i wouldn't want to come arross as selfish by asking too much.
Quote:I have only just learned about threads and i was wondering should I make my loop() method sychronized? If I don't is there a danger that the Timer could fire another ActionEvent before the last loop has finished runningjavax.swing.Timer invokes all of its timer events on one thread. This means that it's not possible to have a second gameplay tick start before the first one is finished; until the first one is finished, the thread is still busy. So there's no need for synchronization to protect specifically from other timer events.Quote:How do people around here feel about people posting the code for a whole program? As I've never had any real feedback about my code it would be hugely benificial to get criticism, but i also undersand it would be time consuming for the people and i wouldn't want to come arross as selfish by asking too much.There's sort of a paradox involved in choosing how much code to show. You're supposed to only post as much code as necessary to find the bug, but since you don't know where the bug is, you may mistakenly post too little code and not show the actually problematic part. The other concern is that faced with pages and pages of code, people will just ignore it.If you can, it's always worth the time to produce a minimal demonstrating example -- as short a piece of REAL (that is, you actually compiled and ran it and it demonstrated the problem) code as possible. This can actually help you find the bug yourself, too.   ;  Thanks Sneftel. I suspected that might be the case with the Timer but wasn't sure so thanks for clearing that up for me.Also to anyone thinking of replying regarding my buffer question, i think was just getting confused by how repaint() worked. I think i understand now and am looking into the bufferStrategy class, so there is no need to reply now. 