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.
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.
Map reading?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: Map reading?
Have you looked at love.image.newImageData and ImageData:getPixel yet? I think you should.
Re: Map reading?
Second link is broken, and I don't see the relevance of the first one, could you put it into context?TechnoCat wrote:Have you looked at love.image.newImageData and ImageData:getPixel yet? I think you should.
Re: Map reading?
Did you read it?
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: Map reading?
Well, uh. Load an imagefile into ImageData and iterate over the pixels to return the color values at each pixel?Lua Hal wrote:Second link is broken, and I don't see the relevance of the first one, could you put it into context?TechnoCat wrote:Have you looked at love.image.newImageData and ImageData:getPixel yet? I think you should.
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}
Who is online
Users browsing this forum: Majestic-12 [Bot] and 47 guests