Love2D Tiled Maps Loading Incorrectly

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
teeter11
Prole
Posts: 27
Joined: Sun Jan 12, 2014 8:48 pm

Love2D Tiled Maps Loading Incorrectly

Post 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

Last edited by teeter11 on Sun Oct 11, 2015 12:06 am, edited 1 time in total.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Love2D Tiled Maps Loading Incorrectly

Post by bobbyjones »

In the first link I see nothing
teeter11
Prole
Posts: 27
Joined: Sun Jan 12, 2014 8:48 pm

Re: Love2D Tiled Maps Loading Incorrectly

Post by teeter11 »

bobbyjones wrote:In the first link I see nothing
fixed it
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Love2D Tiled Maps Loading Incorrectly

Post by bobbyjones »

Why are you using an image to represent a map? Wouldn't using a 2d array or tiled and sti be better?
teeter11
Prole
Posts: 27
Joined: Sun Jan 12, 2014 8:48 pm

Re: Love2D Tiled Maps Loading Incorrectly

Post 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.
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: Love2D Tiled Maps Loading Incorrectly

Post 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

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
teeter11
Prole
Posts: 27
Joined: Sun Jan 12, 2014 8:48 pm

Re: Love2D Tiled Maps Loading Incorrectly

Post 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!
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Love2D Tiled Maps Loading Incorrectly

Post by bobbyjones »

Tbh I think the best way to make a full featured map would be to use tiled and STI
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests