Hey, everybody, this is going to be my first post here so here’s a little background.
I’m self taught and only moderately new to java. I have prior experience with C++ up to about the intermediate level but decided to learn something else. I’ve been reading books, posts and sourcecode to help me get the hang of JG basics. I’ve been reading through Mojang’s Catacomb Snatch while following JGO for a little while but I’m beginning to run into some questions I can’t seem to answer.
TLDR: I’m fairly new and I don’t understand some junk.
1: I feel like a have a fair grasp of how a game loop “should” be structured; I definitely like the fixed timestep version… But I don’t don’t really understand the difference between two of the posts I’ve seen here.
Eli’s fixed timestep loop here: http://www.java-gaming.org/topics/game-loops/24220/view.html
and ra4king’s timestep loop here: http://www.java-gaming.org/topics/about-on-my-main-loop/26222/msg/229028/view.html#msg229028
I understand some of the differences. What I’m really hung up on is the purpose of Eli’s interpolation. I don’t fully understand why it is necessary. And to clarify, I’m going with the assumption in this case that Eli’s code is more precise because both of these loops seem to be well respected and Eli’s is longer.
2: I am not completely clear on some of the ways I’ve seen BufferStrategy implemented. I have followed TheNewBoston’s turorials on Youtube but they seem somewhat lax in the Java Gaming section. http://www.youtube.com/user/thenewboston?feature=watch
I have read Oracle’s documents on BufferStrategy, JFrame, Canvas etc. and I understand how BS works and why it’s great but I am not clear on the differences between JPanel, Canvas and how they act when working with BS. I have seen a BS created from a Window, JFrame, Canvas, and JPanel but I don’t understand why one would be preferred over the other. In Catacomb Snatch Notch uses a JFrame packed with a JPanel yet I see many examples of people creating a BS from a JFrame directly or more often from a Canvas. I am assuming that when you call Canvas.createBufferStrategy(2) it is really calling .createBufferStrategy(2) on the frame it’s packed in but idk. I’m beginning to have dreams related to this question so some clarity would REALLY help.
P.S. I have seen code where .pack() is not used. Why is it preferred or vice versa?
3: While it all seems both concise and clever (imho) I would really love an explanation of why ra4king uses a canvas in the link in number 1. I keep seeing “Oh god DON’T use swing and awt together!” but I’m not seeing a consensus on the issue so I’m at a loss as to why you would use Canvas over JPanel. What I think I understand is that JPanel is best used when using swing components like JButton and that awt has little conflict outside of interactions with those components. Tell me if I’m right: JPanel is more efficient for using components and since most of us on JGO wouldn’t be using them we prefer Canvas because it’s not at the mercy of the EDT. Is that even close?
In addition, I’m assuming that the purpose of ra4king’s daemon thread is because .sleep(int) is more accurate if it’s in constant use.
Lastly, thanks for reading and feel free to help me with forum etiquette cause this is my first real forum post, ever. And I’d love input from either ra4king or Eli here.
TLDR: Read the underlined junk. Also, I’m new, thanks.