Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Storing Images for a Tile Map  (Read 2104 times)
0 Members and 1 Guest are viewing this topic.
Offline 8ballj

Senior Newbie

« Posted 2008-02-28 02:08:29 »

Right now I have a class that draws a tile map.  It has about 10 different BufferedImage objects that are defined in the class.  All the images are stored in a folder on my computer.

BufferedImage Img1 = ...C:/path/img1.bmp
BufferedImage Img2= ...C:/path/img2.bmp

The thing is, I"m going to have over 100 images by the time the game is complete.  Is it normal/standard to have 100+ BufferedImages defined in the field above the constructor in a given class?  Once the images are initialized as the program is loaded, will it have any hinderence on performance during map scrolling later on?

Offline fletchergames

Senior Devvie

« Reply #1 - Posted 2008-02-28 04:03:50 »

It would be more normal to list the image filenames in an external file of some kind.  You can have a text file with lines like "treasure_chest1 = some filename".  It's always good to move the data out of the code.

You can then store the images in a HashMap, hashed by the name of each tile (e.g. treasure_chest1).  This at least saves you from typing all those "BufferedImage whatever = ..." lines.

If the tiles are the same for every map, you will only need to load the images once.  If they are different on different maps, having it set up this way allows you to load new images when you change maps.

I'm sure this can be improved upon, but it's a start.

Having over 100 BufferedImages shouldn't be too bad unless your tiles are really big.  If you don't have much video RAM, you don't really need for all the tiles to be hardware accelerated, so long as the most common are.

If drawing the screen takes longer than scrolling the screen, you won't be able to scroll the screen as fast as you like.  When you scroll the screen, you basically have to redraw the whole thing.  If you have a sufficiently large area in video RAM (which might not even be possible), you could scroll by just changing what part of the area you're displaying.  That might resolve any problems.
Offline 8ballj

Senior Newbie

« Reply #2 - Posted 2008-02-28 05:53:48 »

I don't plan on having more than one type of terrain, and the tiles are 25x25 pixel png's.  I'm also wondering how to get around my paintComponent method looking like:

  • [y]==1) {
    g.drawImage(trees, x, y...)
  • [y]==2) {
   g.draw Image (rock, x,y...

.if (map
  • [y]==100) {

Is this the only way to do it really?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline oNyx

JGO Coder

Medals: 2

pixels! :x

« Reply #3 - Posted 2008-02-28 12:17:07 »

>Is this the only way to do it really?

Nah... usually you just use an array.


And loading... well, you can for example call em tile0001.png, tile0002.png etc and load em in a loop or put several of those tiles into one image. Or name mapping in the editor and packaging/map-remapping during the build process, but that's somewhat complicated and not really required for simple games with rather little media.

弾幕 ☆ @mahonnaiseblog
Offline 8ballj

Senior Newbie

« Reply #4 - Posted 2008-02-28 16:16:46 »

Awesome... never though to of the array thing.  so each idex in the array corresponds to the index of map
  • [y].  I'm just using a BufferedImage[ ] array at this point.  Is that the simplest array to use (as opposed to a Vector or ArrayList?).  Thanks everyone again for the fast help!
Offline oNyx

JGO Coder

Medals: 2

pixels! :x

« Reply #5 - Posted 2008-02-28 16:30:16 »

Ye, arrays are faster and far simpler than any of the collection classes. If you can use arrays without having to jump through hoops, you should really use em. For this kind of thing the number of elements is known beforehand and the size remains as it is for the whole run.

弾幕 ☆ @mahonnaiseblog
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

SHC (30 views)
2015-08-01 03:58:20

Jesse (20 views)
2015-07-29 04:35:27

Riven (40 views)
2015-07-27 16:38:00

Riven (22 views)
2015-07-27 15:35:20

Riven (25 views)
2015-07-27 12:26:13

Riven (15 views)
2015-07-27 12:23:39

BurntPizza (37 views)
2015-07-25 00:14:37

BurntPizza (46 views)
2015-07-24 22:06:39

BurntPizza (31 views)
2015-07-24 06:06:53

NoxInc (37 views)
2015-07-22 22:16:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!