Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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  
  Encode data into pixels in an image  (Read 1867 times)
0 Members and 1 Guest are viewing this topic.
Offline StonePickaxes

JGO Coder

Medals: 5
Projects: 2

Nathan Kramber

« Posted 2012-07-30 18:05:54 »

What I want to do is make a level in by drawing certain colored pixels and having the Level class decode this into an array of tiles, and if I want an entity to spawn on a certain tile, put the info necessary into the right pixel on the .png for the level.

Is this possible at all? How do I put the data into the image? How do I read the data from the image?

If this is possible, thanks, if not, sorry for wasting your time.

 | Nathan

Check out my website!
Offline Ultroman

JGO Knight

Medals: 25
Projects: 1

Snappin' at snizzes since '83

« Reply #1 - Posted 2012-07-30 18:07:03 »

You just get the raster from the image, and change the color-data.

- Jonas
Offline UprightPath
« Reply #2 - Posted 2012-07-30 23:19:26 »

To load: Get the pixel data from the image (Depending on what library you're using the method to get the data this will differ, though not too considerably), then you iterate through each pixel and get the color data from it. From there, you should be able to take information out of that value (Either by using a set of if statements, a switch, maybe even using several arrays filled with the corresponding data you need, etc.)

To edit/paint: This is more complicated. If you're using (Which I've used for a simplified version of this) then you just have to be very specific about how you fill in the values of the color (Use the 'More >>' to be able to pick a specific color value). Then you just fill in the specific pixel with that data. The main issue is that if you're using each color channel (including Alpha) to mean something different you have to get that color (Using the eye drop) edit it using the color panel, then refill it in.

For anything complicated, attempting to draw it all using is probably going to be more difficult to keep straight than writing your own tile editor system (Even if it outputs data in the form of an image).

For other information about doing this: This post is about the same thing and so is this thread.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-07-31 01:47:38 »

Or if that's too complicated, create a BufferedImage and draw on it based on your data. I usually use it for small retro style pic. But you better use Ultroman's.

Offline Damocles
« Reply #4 - Posted 2012-07-31 07:54:01 »

Also: for ease create an index-palette on the picture itself.

I usually create a row of differenly colored pixels in the top left.
Treating the first line of the picture as reference.
A Magenta colored pixel (255,0,255) marks the end of the index.

Now you can just easily pic the appropriate color when drawing the map, and
add more later if needed.

When loading, you first analyse this first row to get the colorvalues,
and map it to your object-index.
color #0 empty
color #1 sand
color #2 rock
color #3 spawn monster.

The top row is ignored, the rest of the picture defines the tile-level.
Pages: [1]
  ignore  |  Print  

EgonOlsen (79 views)
2018-06-10 19:43:48

EgonOlsen (59 views)
2018-06-10 19:43:44

EgonOlsen (78 views)
2018-06-10 19:43:20

DesertCoockie (261 views)
2018-05-13 18:23:11

nelsongames (159 views)
2018-04-24 18:15:36

nelsongames (158 views)
2018-04-24 18:14:32

ivj94 (901 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (813 views)
2018-03-24 14:43:53

Solater (177 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!