Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (516)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (577)
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 Game Maps as Images - What about multiple layers?  (Read 2198 times)
0 Members and 1 Guest are viewing this topic.
Offline SeanSeanston

Senior Newbie





« Posted 2012-04-17 13:41:57 »

So I'm looking at implementing a system of saving/loading my 2D platformer's levels using simple image files to store the tile data etc. since it seems a quick and practical way of doing so, and for something like Ludum Dare it seems popular.
I myself have made a somewhat proper level editor before for a top-down shooter in C++, but that was a lot of hassle at times and it would be nice to get something quite functional up and running before committing to spending time on something like that rather than the actual game if at all possible.

While an image file works fine for a 2D tile array, I'm wondering about how you might go about doing slightly more complicated things like placing enemies?
An enemy or any entity could be a coloured pixel in an image, but then what about the underlying tile? You'd have to either decide the underlying tile will always be empty, some specific tile, or perhaps the same as the tile to the left of it etc. Granted, for a platformer this doesn't matter as much since most of the time anything behind an enemy will simply be a blank space but for a better looking map you might want to put non-collidable background tiles, perhaps if you were in a cave or something, and then we'd run into problems.

How might you go about something like that then? Allowing a simple image to place map tiles and enemies but not have the enemies prevent you from deciding on the underlying tile? Does anyone ever tend to bother, preferring to just make a proper level editing program when a game requires that ability?
One idea I just had would be a separate image with the same map tile image on it, but with enemy positions overlaid and when the game was loading the map it could simply ignore the map tiles and place the enemies in the right positions while still allowing a human to easily place objects with a feel for where they are in the map. Might be slightly messy though, but I guess it would work.
Any better ideas for quick and easy level editing without resorting to a full editor?
I also do know about Tiled which seems quite popular, but I haven't tried to learn how to use that just yet.
Offline _Al3x

Senior Duke


Medals: 7


Indie Games FTW!


« Reply #1 - Posted 2012-04-17 13:49:00 »

Hello! Smiley

I think of an easy and fast way of doing that. Use 2 images of the same size! One with all the tiles, and the other with some color you'll never use to "fill the gasps" and other colours for other entities, like enemies or npcs.
Easy and fast Smiley

Have a nice day!

Offline UprightPath
« Reply #2 - Posted 2012-04-17 13:51:53 »

Images are difficult to do if you're going to be using simple colour information. Once you start having to differentiate between the differing values of 'red' to figure out what you were doing. Really, you have to consider whether you'll remember what all of the stuff you do means if you come back at a later date. If you're going to spend more time figuring out that "Oh, 255 red means this and 127 red means that" then you'll probably be better served to use something else.


However, if you really want to do it you can be really fancy about it you can use the three different colours to mean different things. Like, if you're not going to drawing these yourself.

Have red indicate the 'background' (You get 255 of them, and it could be used to indicate passability if you don't want to use the alpha channel), blue indicate your 'enemy', green indicate items and then your alpha channel being a binary 'passable/impassable', or if you need a pathfinder, you can treat it as a 'cost' variable. Then, in a single bitmap or PNG you've got everything you need, depending on how you want it.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SeanSeanston

Senior Newbie





« Reply #3 - Posted 2012-04-17 14:03:04 »

Have red indicate the 'background' (You get 255 of them, and it could be used to indicate passability if you don't want to use the alpha channel), blue indicate your 'enemy', green indicate items and then your alpha channel being a binary 'passable/impassable', or if you need a pathfinder, you can treat it as a 'cost' variable. Then, in a single bitmap or PNG you've got everything you need, depending on how you want it.

Ah yes... the alpha channel came to my mind (just in passing... wasn't really sure how it might be used) but I hadn't thought about using the separate RGB values like that.

I suppose that's about the most information you could reasonably put in an image. Shouldn't be overly hard to follow then as long as you keep an organized list of what each colour means.

Thanks for that, I'll have a think about it and see what I want to do. Might keep it simple for now persecutioncomplex
Offline UprightPath
« Reply #4 - Posted 2012-04-17 14:16:02 »

Not nearly so easy as you think.

After you get to about six shades of a colour it gets hard to differentiate them on a monitor.

Offline SeanSeanston

Senior Newbie





« Reply #5 - Posted 2012-04-18 10:08:54 »

Hmmmm... yes I suppose if you had to keep checking what colour a pixel was and then looking it up in a table, you'd be defeating a lot of the purpose of using a simple image. Well, given I'm trying to making a platformer, I suppose there's no real major need for a map tile to go behind an entity.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (32 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (41 views)
2014-10-26 19:37:11

Luminem (22 views)
2014-10-26 10:17:50

Luminem (27 views)
2014-10-26 10:14:04

theagentd (33 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (58 views)
2014-10-16 15:22:06

Norakomi (47 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!