Results 1 to 10 of 10
  1. #1
    sgthale is offline Member
    Join Date
    Apr 2011
    Posts
    48
    Rep Power
    0

    Post Simple Tile Game Question

    Im making a game that has an array of 128x128 each holding a specific tile type. The game will loop and draw the tile type. Is there a better faster way to go through this instead of redrawing every single block every frame?

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    What are tile classes? Are they individual jpanels you draw on? You may only have to update the specific tiles that change, and not every tile. It's really implementation dependant, but drawing 128^2 tiles each time seems like a design flaw to me.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm not sure what you're using as your game engine, but you may wish to somehow tag the tiles that need to be repainted, and then when you loop through the tiles, only repaint the tagged ones, of course untagging them as you go.

  4. #4
    sgthale is offline Member
    Join Date
    Apr 2011
    Posts
    48
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    I'm not sure what you're using as your game engine, but you may wish to somehow tag the tiles that need to be repainted, and then when you loop through the tiles, only repaint the tagged ones, of course untagging them as you go.

    That could work except for the fact that the camera might be moving. Its a simple 2D engine. I was wondering if there was a way in which you draw the map once and save the entire map as a "snapshot" image. Then you can just move the snapshot instead of redrawing the whole thing again. And then you would be able to update the map by painting ON the snapshot. Is there such a way? I am using awt

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,275
    Rep Power
    25

    Default

    Look at using a BufferedImage to create/draw an image.

  6. #6
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Expanding on Norm's answer:
    If your tiled world never or rarely changes, you could just draw the entire world in a BufferedImage once and then use that image to draw to the screen. Since drawImage is an expensive call, this would be the most efficient way.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,758
    Rep Power
    19

    Default

    The only thing to note on drawing the whole world is how big (number of pixels) it is.
    But that'll be your call based on your expected memory footprint.

    But it is the easiest solution.

  8. #8
    sgthale is offline Member
    Join Date
    Apr 2011
    Posts
    48
    Rep Power
    0

    Default

    Yeah that seems like what I was looking for. Im still running around in the internet looking for a tutorial specifically for this...

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,758
    Rep Power
    19

    Default

    You could try some of the map drawing stuff over at gamedev.net.
    Not sure how much Java stuff there is, but it might help you understand the logic behind it a bit better.

  10. #10
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

Similar Threads

  1. need a simple java game
    By Shashwat in forum New To Java
    Replies: 1
    Last Post: 01-03-2011, 02:42 PM
  2. Concept of Tile map via database
    By GrInd3r in forum New To Java
    Replies: 0
    Last Post: 12-08-2010, 05:18 PM
  3. Need help with simple game! *collision*
    By CNew in forum New To Java
    Replies: 1
    Last Post: 12-05-2010, 12:09 AM
  4. simple game programming help
    By b.m in forum New To Java
    Replies: 0
    Last Post: 11-25-2010, 05:16 PM
  5. Simple Game example
    By mayuresh34 in forum CLDC and MIDP
    Replies: 1
    Last Post: 10-08-2009, 01:21 PM

Tags for this Thread

Posting Permissions

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