Page 1 of 1

Love2D Tiled Maps Loading Incorrectly

Posted: Sat Oct 10, 2015 11:10 pm
by teeter11
So I ran some tests and I figured out that my mapload method was loading the map from a picture incorrectly.

I don't want to use mapPixel but instead make my own map loading method.

So im trying to get each pixel for each row on the line and create a value in a table for it. I think the way i made my table is incorrect. So i was wondering if anyone could look at my code and tell me whats wrong.

The map is just getting loaded from this incorrectly, i looked at the table (mapData) and it was incorrectly loaded.

Here is what im trying to load :

(supposed to be 16x16)

http://imgur.com/5kulseh

Here is what i get :

http://imgur.com/a/lHviN

Any help would be awesome thanks!

Code:

Code: Select all


function mapLoad()
	
	local mapPixels = love.image.newImageData("/rec/maps/woodtest.png")
	
	local pixelX = 1
	local pixelY = 1
	
	mapToDraw = true
	
	for i = 1,15 do
	
		for i = 1,15 do
		
			mapR , mapG , mapB , mapA = mapPixels:getPixel(pixelX - 1,pixelY - 1)
			
			if mapR == 0 and mapG == 127 and mapB == 14 then
				table.insert(mapData, "grass")
			elseif mapR == 124 and mapG == 73 and mapB == 38 then
				table.insert(mapData, "darkoakwood")
			elseif mapR == 150 and mapG == 88 and mapB == 46 then
				table.insert(mapData, "oakwood")
			end
										
			if pixelX == 16 then
				pixelX = 1
			else 
				pixelX = pixelX + 1	
			end
				
		end
		
		if pixelY == 16 then
			pixelY = 1
		else		
			pixelY = pixelY + 1	
		end		
		
	end
	
	pY = pixelY
	pX = pixelX
	
	return
end


Re: Love2D Tiled Maps Loading Incorrectly

Posted: Sat Oct 10, 2015 11:25 pm
by bobbyjones
In the first link I see nothing

Re: Love2D Tiled Maps Loading Incorrectly

Posted: Sun Oct 11, 2015 12:05 am
by teeter11
bobbyjones wrote:In the first link I see nothing
fixed it

Re: Love2D Tiled Maps Loading Incorrectly

Posted: Sun Oct 11, 2015 12:30 am
by bobbyjones
Why are you using an image to represent a map? Wouldn't using a 2d array or tiled and sti be better?

Re: Love2D Tiled Maps Loading Incorrectly

Posted: Sun Oct 11, 2015 12:35 am
by teeter11
bobbyjones wrote:Why are you using an image to represent a map? Wouldn't using a 2d array or tiled and sti be better?
This is the way i felt that would be the best. This code turns the image into an array.

Re: Love2D Tiled Maps Loading Incorrectly

Posted: Sun Oct 11, 2015 12:41 am
by Beelz
I would try using a table like:

Code: Select all

mapTable = {}

function LoadMap(map)
     local line = love.filesystem.lines(map)
     for i=1,#line do 
           mapTable.row[i] = {}
           for j = 1, line:len() do
               mapTable.row[i].column[j] = {}
               table.insert(mapTable.row[i].column[j],string.sub(line, j, j)) -- i = each line // j = each char
           end
     end
end

Re: Love2D Tiled Maps Loading Incorrectly

Posted: Sun Oct 11, 2015 1:01 am
by teeter11
Beelz wrote:I would try using a table like:

Code: Select all

mapTable = {}

function LoadMap(map)
     local line = love.filesystem.lines(map)
     for i=1,#line do 
           mapTable.row[i] = {}
           for j = 1, line:len() do
               mapTable.row[i].column[j] = {}
               table.insert(mapTable.row[i].column[j],string.sub(line, j, j)) -- i = each line // j = each char
           end
     end
end
Okay ill try this out, thanks!

Re: Love2D Tiled Maps Loading Incorrectly

Posted: Sun Oct 11, 2015 1:24 am
by bobbyjones
Tbh I think the best way to make a full featured map would be to use tiled and STI