Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Tolls

Thread: Need a experienced Java dev opinion ! :O

  1. #1
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Exclamation Need a experienced Java dev opinion ! :O

    Im making a game in 2D and im having some problems ... first of all I need to have quiet big maps ... and my maps are made of "tile" objects with size of 40x40 pixels ... In each "map" there is an
    tile[1000][1000] array, witch objects i modify when i make the array ... The main character is supposed to be centered at all times ... Iv thought about 3 ways of doing this :

    1. put all objects in a JScrollPane and center the main character.
    2. Only paint enoght objects to fill the screen then change the properties of the objects as the character walks traversing trough the array...
    3. In some way paint the objects that are supposed to show outside of the Panel (with double buffering) and then change put the image in the panel ... (is it possible to paint only some pixels of an object?)

    Is there any better way to store the map data?(will be given by a server)
    What way/s would be the best to achive what im trying to do?

    Also Iv written methods inside of all objects that checks if the mouse is near and if they where clicked ... but to check this I have to loop though all objects ... is there a better way to do this with hashmap? how would I set the key to a intervall where the object is ?


    Thanks ... and please only comment if you think you have a valid solution to one or more of my problems =P

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,123
    Rep Power
    20

    Default

    Stick the character in the middle of the screen.
    As they move from one tile to another scroll the screen in that direction.
    The screen displayed will be a window onto a larger view of the world.
    The size of this view will depend on the memory footprint you want...you won't be able to do the full 40000 x 40000 px map for example.
    So that means as they move you need to be prepared to draw the next version of the map.

    Does that make sense?

  3. #3
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default

    Quote Originally Posted by Tolls View Post
    Stick the character in the middle of the screen.
    As they move from one tile to another scroll the screen in that direction.
    The screen displayed will be a window onto a larger view of the world.
    The size of this view will depend on the memory footprint you want...you won't be able to do the full 40000 x 40000 px map for example.
    So that means as they move you need to be prepared to draw the next version of the map.

    Does that make sense?
    So basically ... Im not totally with you so I make the characters position fixed in the middle of the JScrollPane... and then "The screen displayed will be a window onto a larger view of the world." so you mean that I will select enought objects in my map array to fill the screen?(beacuse the array would be my "larger veiw of the world"?) I have no idea what a memory footprint is but i guess its how much memory that is used?

    So basically I paint tiles to fill the screen and a little more.. and then at the same time i prepair a new image for all posible directions? hummf ... programmetically speaking ... how would be a good way to do that? Thanks

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,123
    Rep Power
    20

    Default

    It's sort of number 3 in your OP.
    Your memory footprint is how much memory your app is going to take up.
    40000 x 40000 px is 1.6Gpx, which is about 5Gb of memory (say 3 bytes per pixel, could be less, I can never remember).

    Anyway, that aside.
    You know how big the window you're displaying to (JPanel size).
    Figure out how many tiles fit neatly into that space.
    Now, add a buffer round the outside.
    Draw this to an image.
    This gives you a picture that's bigger than can be displayed.

    So. When the character moves left you can use this picture to scroll smoothly left one square.
    While that's going on you can draw a new picture based on this new position.
    Once drawn, this can replace the old picture.

    There used to be good articles on gamedev.net for this sort of thing.
    Some of them may even be for Java, but even the C ones will explain the concepts of map scrolling.

  5. #5
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default

    Nice =P thanks man i LOVE you now ;) anyway so if my JScrollPane is 800x600 it will be 20x16 objects to fill the Pane ... so then i draw 24x20 objects (witch will be bigger) and put the image in to the JScrollPane ? =) Iv never been to that site but i'll definitely check it out =)

  6. #6
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default

    But if I do it this way ... when would I do the painting ... when the JScrollPane has nothing more to show?

  7. #7
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,123
    Rep Power
    20

    Default

    I wouldn't use a JScrollPane.
    Just use a JPanel.

    I think it's the paint() method you override (someone else might be able to confirm that one).
    The Panel simply draws the part of the underlying picture that would be relevant.

    This would be called by whatever moveCharacter functionality you have.

    Character moves -> calculate new centre point for the painting -> repaint -> redraw the base picture in the background (somehow).

    That last step may only need to be done when you get close to the edge of your base picture.
    santa likes this.

  8. #8
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default

    I think it'll be the paintComponent if i wish to paint a Jpanel... I think I have a good idea of what to do :P now i just have to figure out how to do it in java ;) thanks man ... you saved my life ;)

Similar Threads

  1. Experienced Programmer, novice at Java
    By CuddlyKittens11 in forum Introductions
    Replies: 16
    Last Post: 04-25-2011, 11:43 AM
  2. Java project for beginners/experienced
    By Si1ver in forum Jobs Offered
    Replies: 0
    Last Post: 04-13-2011, 12:09 AM
  3. Replies: 0
    Last Post: 03-17-2011, 10:50 PM
  4. need opinion on public static final etc ...
    By mac in forum New To Java
    Replies: 4
    Last Post: 05-20-2010, 10:54 AM
  5. Replies: 0
    Last Post: 07-04-2008, 10:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •