Drawing lines around tiles

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.
User avatar
Gunroar:Cannon()
Party member
Posts: 141
Joined: Thu Dec 10, 2020 1:57 am

Drawing lines around tiles

Post by Gunroar:Cannon() » Sat Jan 16, 2021 7:42 am

How can I easily draw lines around tiles (to give it this cartoonish look)? Like tiles in the middle won't have any lines draw around them. Tiles on the ceiling will have a line drawn at their bottom. Tiles at the floor will have lines drawn at their top and tiles at corners will have lines drawn to theirs sides and top/bottom. This is a platformer like game where tiles get placed and destroyed a lot. thnx
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
    for x, enemy in ipairs(self.allEnemies) do
        self:Cannon(enemy)
    end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow

User avatar
Gunroar:Cannon()
Party member
Posts: 141
Joined: Thu Dec 10, 2020 1:57 am

Re: Drawing lines around tiles

Post by Gunroar:Cannon() » Tue Jan 19, 2021 6:28 am

So no ideas or not enough info?
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
    for x, enemy in ipairs(self.allEnemies) do
        self:Cannon(enemy)
    end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow

User avatar
Xii
Citizen
Posts: 64
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: Drawing lines around tiles

Post by Xii » Tue Jan 19, 2021 8:47 am

Usually that's embedded into the tileset graphic, and the technique to lay tiles correctly is called Marching Squares.
I think your question is too vague for more specific assistance.

User avatar
Gunroar:Cannon()
Party member
Posts: 141
Joined: Thu Dec 10, 2020 1:57 am

Re: Drawing lines around tiles

Post by Gunroar:Cannon() » Tue Jan 19, 2021 1:31 pm

Thnx for pointing me in the right direction. :)
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
    for x, enemy in ipairs(self.allEnemies) do
        self:Cannon(enemy)
    end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow

User avatar
Gunroar:Cannon()
Party member
Posts: 141
Joined: Thu Dec 10, 2020 1:57 am

Re: Drawing lines around tiles

Post by Gunroar:Cannon() » Tue Jan 19, 2021 4:23 pm

Ok,so I found a library( https://github.com/phobus/LuaMarchingSquares) But... I'm a little confused ... like always :P . Like what is "data" for? I know the answer was probally in the Wikipedia site somewhere but I couldn't figure it out. I want to ...like ... draw a black line around a square image with love.graphics.line so the image is outlined without making a new image( which looks possible with the whole Marching square thing) so pls explain more...maybe an example (explanation will be enough though). Thnx.
I hope I'm not getting the wrong idea.
(P.s: I don't use a tileset. And the map also isn't gotten from a tiled map (or any map) editor. The tiles get destroyed and replaced by the player a lot)
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
    for x, enemy in ipairs(self.allEnemies) do
        self:Cannon(enemy)
    end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow

User avatar
Xii
Citizen
Posts: 64
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: Drawing lines around tiles

Post by Xii » Tue Jan 19, 2021 8:52 pm

Draw up and example image manually with before and after of what you have and what you want.

User avatar
Gunroar:Cannon()
Party member
Posts: 141
Joined: Thu Dec 10, 2020 1:57 am

Re: Drawing lines around tiles

Post by Gunroar:Cannon() » Tue Jan 19, 2021 9:05 pm

Hehe...(sweat-smile emoji). I did what I wanted to avoid and did the loops so I fixed it...(thnx for helping tho). I hope this illustrates what I meant (didn't try this first because I was checking if there was a more efficient way so thnx)

Code: Select all

local lgetColor = love.graphics.getColor
local lsetColor = love.graphics.setColor
local function drawAroundTile(x,y,w,h,color,data)
    local r,g,b,a = lgetColor()
    lsetColor(color)
    local drawline = love.graphics.line
    local linew = 0
    local x2, y2 = x+w-linew, y+h-linew
    
    local old = love.graphics.getLineWidth()
    love.graphics.setPointSize(10)--
    love.graphics.setLineWidth(Linew or 0)
    if data.up then
        drawline(x,y,x2,y)
    end
    
    if data.down then
        drawline(x,y2,x2,y2)
    end
    
    if data.left then
        drawline(x,y,x,y2)
    end
    
    if data.right then
        drawline(x2,y,x2,y2)
    end
    
    lsetColor(r,g,b,a)
    love.graphics.setLineWidth(linew)
end

local black = getColor("black")
local dirs = { {1,0}, {-1,0}, {0,1}, {0,-1} }
local vals = { 
    [-1] = {[0]="left"},
    [1]  = {[0]="right"},
    [0]  = {
        [1]="down",
        [-1]="up"
    }
}

function highlightTile(x,y,w,h,color,map)
    local tx, ty = x/w, y/h
    local grid = (map or game.map).grid
    local tile
    local data = {}
    local d, dd, t, dx, dy
    
    for d = 1, 4 do
        dd = dirs[d]
        dx, dy = dd[1], dd[2]
        t = grid[tx+dx] and grid[tx+dx][ty+dy]
        if t and t.isBackground then
            data[vals[dx][dy]] = true
            data.used = true
        end
    end
    
    if data.used then
        drawAroundTile(x,y,w,h,color or black,data)
    end
    data = nil
    grid = nil

end
Now my only question is how to make lines in love thicker (by height)?
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
    for x, enemy in ipairs(self.allEnemies) do
        self:Cannon(enemy)
    end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow

User avatar
Xii
Citizen
Posts: 64
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: Drawing lines around tiles

Post by Xii » Wed Jan 20, 2021 8:32 am

Gunroar:Cannon() wrote:
Tue Jan 19, 2021 9:05 pm
Now my only question is how to make lines in love thicker (by height)?
love.graphics.setLineWidth

User avatar
Gunroar:Cannon()
Party member
Posts: 141
Joined: Thu Dec 10, 2020 1:57 am

Re: Drawing lines around tiles

Post by Gunroar:Cannon() » Wed Jan 20, 2021 12:00 pm

Oh, it sets the height too? Thnx!
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
    for x, enemy in ipairs(self.allEnemies) do
        self:Cannon(enemy)
    end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow

User avatar
darkfrei
Party member
Posts: 109
Joined: Sat Feb 08, 2020 11:09 pm

Re: Drawing lines around tiles

Post by darkfrei » Wed Jan 20, 2021 12:56 pm

Gunroar:Cannon() wrote:
Tue Jan 19, 2021 4:23 pm
Ok,so I found a library( https://github.com/phobus/LuaMarchingSquares)
Very nice library!
But somehow I got wrong connections:
Attachments
2021-01-20T13_44_01-Untitled.png
2021-01-20T13_44_01-Untitled.png (197.66 KiB) Viewed 2917 times
2021-01-20T13_44_01-Untitled-02.png
2021-01-20T13_44_01-Untitled-02.png (206.7 KiB) Viewed 2917 times
LuaMarchingSquares-01.love
(3.39 KiB) Downloaded 58 times

Post Reply

Who is online

Users browsing this forum: No registered users and 64 guests