3
\$\begingroup\$

I'm fairly new to game development. I've been messing around with Slick2D. My map consists of rectangular objects. I want to use an image to represent my map, similar to this:

Level image

How could I generate a level from that image? As I said, I'm new to game development and am not familiar with terminology or procedures.

Bonus question: How could I also generate non-rectangular game objects from it?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Lots of ways to approach this. For example, you could parse the file and at every location where there's blue, you could create a object in your game. Maybe you can be more specific about how you want to use this? Tell us what you want to put in and what you want to get out. Be specific. Ideally you would try something first, then ask about it. Making a level using that image is certainly possible, but you should tell us what approach you want to use. \$\endgroup\$
    – House
    May 6, 2014 at 23:08
  • 1
    \$\begingroup\$ Does it have to be an image? Maybe it is easier to use a simple text file instead? Moreover, Slick2D supports tile maps created with the Tiled editor. \$\endgroup\$
    – Raginmari
    Aug 5, 2014 at 7:40

1 Answer 1

2
\$\begingroup\$

Though the idea of what to do with your data is vague, reading image data and operating on it is straightforward. See the ImageBuffer.getRGBA docs.

public byte[] getRGBA()
Retrieve the raw data stored within the image buffer
Returns: The raw data in RGBA packed format from within the image buffer

You have other options as well, such as ImageIOImageData.loadImage

The important part is, load the image, get the data. Once you have that byte array (as well as some other handy info from getHeight() and getWidth) iterate over it and generate your level geography. The options for exactly what you generate are infinite.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .