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: 1085
Joined: Thu Dec 10, 2020 1:57 am

Drawing lines around tiles

Post by Gunroar:Cannon() »

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
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Drawing lines around tiles

Post by Gunroar:Cannon() »

So no ideas or not enough info?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
Xii
Party member
Posts: 137
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: Drawing lines around tiles

Post by Xii »

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: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Drawing lines around tiles

Post by Gunroar:Cannon() »

Thnx for pointing me in the right direction. :)
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Drawing lines around tiles

Post by Gunroar:Cannon() »

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)
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
Xii
Party member
Posts: 137
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: Drawing lines around tiles

Post by Xii »

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: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Drawing lines around tiles

Post by Gunroar:Cannon() »

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)?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
Xii
Party member
Posts: 137
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: Drawing lines around tiles

Post by Xii »

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: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Drawing lines around tiles

Post by Gunroar:Cannon() »

Oh, it sets the height too? Thnx!
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Drawing lines around tiles

Post by darkfrei »

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 6676 times
2021-01-20T13_44_01-Untitled-02.png
2021-01-20T13_44_01-Untitled-02.png (206.7 KiB) Viewed 6676 times
LuaMarchingSquares-01.love
(3.39 KiB) Downloaded 189 times
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 51 guests