Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How exactly does random block generation work in 2D/3D worlds?

  1. #1
    Member
    Join Date
    Jan 2013
    Posts
    34
    My Mood
    Busy
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Angry How exactly does random block generation work in 2D/3D worlds?

    Hey, I've had this question for a LONG time. I've been searching the internet for tutorials/answers, but no results. What makes this frustrating for me is that I only see unrelated answers, or people putting videos on Youtube showing them testing 2D random world generation. And there's no tutorials?!

    Well, sure, you could render a couple blocks in random places. But how to people achieve this rendering 100s, if not 1000s of blocks and the game run smoothly, no lag?! So my questoins are:
    Exactly how are they randomly generated at all, and second, how are so many objects in a single class not causing lag? And third, how are they storing the block objects? ArrayLists or Arrays? If someone has the answer, I would love to know! Thanks in advance!


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: How exactly does random block generation work in 2D/3D worlds?

    I'm not sure what you mean by "blocks" or what graphics library you're using, so you may wish to clarify this as well as provide any other details that can help us help you.

    I will take a stab though with the caveat that I'm not a professional programmer, not by any means.

    My thoughts:

    • If you mean the Swing GUI library, and you are asking about rendering many fixed objects, this can easily be done by drawing them in a BufferedImage and then using that image as a background image for a GUI, drawing it as either an ImageIcon in a JLabel or drawn in a JComponent's paintComponent method. Then moving sprites can be drawn in the same paintComponent method but with variable position.
    • Always remember to separate program logic from view. Although this adds a level of indirection, it really shouldn't slow things too much.
    • If you are asking about serious game creation, then likely you'll want to use a different GUI library than Swing and use an already created and optimized game engine.

  3. #3
    Member
    Join Date
    Jan 2013
    Posts
    34
    My Mood
    Busy
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default Re: How exactly does random block generation work in 2D/3D worlds?

    By blocks I mean 2D tiles. And I'm using LWJGL/Slick2D, by the way. Check out a video on Youtube named Java 2D Random Tile Generation by Radnyxx Gentleman. It's pretty much what I'm talking about. If you acknowledge a solution, just give me some hints or psuedo code. Remember, I'm wondering about how so many are rendered without lag at all.

Similar Threads

  1. PDF generation
    By deependeroracle in forum JDBC & Databases
    Replies: 2
    Last Post: June 26th, 2012, 10:29 AM
  2. [SOLVED] Not sure how to work with multiple delimiters. Also, there is random tabbing.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 17th, 2012, 08:23 PM
  3. Generation of random number using random class
    By JavaPF in forum Java SE API Tutorials
    Replies: 1
    Last Post: December 7th, 2011, 05:46 PM
  4. Can a for loop work with random number?
    By humdinger in forum Loops & Control Statements
    Replies: 7
    Last Post: January 10th, 2010, 10:06 PM
  5. Generation of random number using random class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 16th, 2009, 06:10 AM

Tags for this Thread