Map reading?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Lua Hal
Citizen
Posts: 58
Joined: Tue Jul 12, 2011 10:30 pm

Map reading?

Post by Lua Hal »

In my games so far, I've always read the map from a text file, but I've found as the maps get bigger it is more difficult to understand what the map will look like, so alternatively I'd like to read from an image file, where different colored pixels stand for a tile.
Unfortunately, I have no idea to do this. :death:

For my skill level, how would I convert an image like this:

(255,0,0)(0,0,255)
(255,0,255)(0,255,0)

into a table like this:

table["2x1"] would return:

{0,0,255}

In other words, a table of tables representing the RGB of each pixel in a picture file ( I would be willing to work with any file type ) Accessible via a coordinate string.

Any help is appreciated.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Map reading?

Post by TechnoCat »

Have you looked at love.image.newImageData and ImageData:getPixel yet? I think you should. :awesome:
User avatar
Lua Hal
Citizen
Posts: 58
Joined: Tue Jul 12, 2011 10:30 pm

Re: Map reading?

Post by Lua Hal »

TechnoCat wrote:Have you looked at love.image.newImageData and ImageData:getPixel yet? I think you should. :awesome:
Second link is broken, and I don't see the relevance of the first one, could you put it into context?
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Map reading?

Post by vrld »

Did you read it?
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Map reading?

Post by TechnoCat »

Lua Hal wrote:
TechnoCat wrote:Have you looked at love.image.newImageData and ImageData:getPixel yet? I think you should. :awesome:
Second link is broken, and I don't see the relevance of the first one, could you put it into context?
Well, uh. Load an imagefile into ImageData and iterate over the pixels to return the color values at each pixel?

Code: Select all

image = love.image.newImageData("awesomemap.png")

--I wonder what kind of tile is at (1,2)? (0,0) being the upper-left.
local r, g, b, a = image:getPixel(1,2)
1_2_tile = {r,g,b,a}
User avatar
Lua Hal
Citizen
Posts: 58
Joined: Tue Jul 12, 2011 10:30 pm

Re: Map reading?

Post by Lua Hal »

vrld wrote:Did you read it?
Oops, I found some relevant information in
ImageData:getPixel
Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 47 guests