Line draw wierdness

When I draw a line, it’s not drawing the same thickness all the way across. How can I attatch an image of the screenshot?

You could just post the code and let us try it and see if we get the same results.

Here’s the code, you’d have to substitue your own graphics. the issue is in tab Tile draw.

https://dl.dropboxusercontent.com/u/167728467/FullSizeRender.jpg

It’s like a layer issue at the corners of each tile there 4 meet…

--tab main
function setup()
    
    spriteMode(CORNER)
    --file = os.getenv("HOME").."/Documents/map1.txt.png"
    file = os.getenv("HOME").."/Documents/Dropbox.assetpack/map1.txt.png"
    BattleMap = Map(file)
end

function draw()
    background(0,0,0)
    BattleMap:draw()
end

function touched(touch)
    BattleMap:touched(touch)
end

--tab Map
Map = class()

function Map:init(file)
    --tiles
    self.Tile = {}
    self.Unit = {}
    self.player = 1 --alternates betwen player 1 and 2
    self.phase = "move" --move, target, cobat, retreat, advance, reinforce
    counter = 1
    unitcounter = 1
    io.input(io.open(file,"r"))

    for FileLine in io.lines() do
        local thistile = split(FileLine, ",")
        local x = tonumber (thistile[1])
        local y = tonumber (thistile[2])
        local terrain = thistile[3]
        local vp = thistile[4]
        local feature = thistile[5]
        local owner = thistile[6]
        local unittype = thistile[7]
        local rivern = thistile[8]
        local riverne = thistile[9] 
        local rivere = thistile[10]
        local riverse = thistile[11]
        local rivers = thistile[12]
        local riversw = thistile[13]
        local riverw = thistile[14]
        local rivernw = thistile[15]
        local roadn = thistile[16]
        local roadne = thistile[17]
        local roade = thistile[18]
        local roadse = thistile[19]
        local roads = thistile[20]
        local roadsw = thistile[21]
        local roadw = thistile[22]
        local roadnw = thistile[23]
        
        self.Tile[counter] = Tile(x, y, terrain, vp, feature, owner, unittype, rinern, riverne, rivere, riverse, rivers, riversw, riverw, rivernw, roadn, roadne, roade, roadse, roads, roadsw, roadw, roadnw)
        counter = counter + 1

        --units
        if unittype ~= 'none' then  
            print(unittype)
            self.Unit[unitcounter] = Unit(x, y, unittype, owner)
            unitcounter = unitcounter + 1
        end
    end
end

function Map:draw() 
    for y=1,20 do
        strokeWidth(5)
        stroke(90, 90, 90, 100)
        line(1,y*48,20*48,y*48)
    end
    
    for x=1,20 do
        strokeWidth(5)
        stroke(90, 90, 90, 100)
        line(x*48,1,x*48,20*48)
    end
    
    for i,v in pairs(self.Tile) do
        self.Tile[i]:draw()
    end

    for i,v in pairs(self.Unit) do
        self.Unit[i]:draw()
    end

end

function Map:touched(touch)   
    for i,v in pairs(self.Unit) do
        self.Unit[i]:touched(touch)
    end
    
    for i,v in pairs(self.Tile) do
        self.Tile[i]:touched(touch)
    end
    
    --game phases:
    --collect income
    --german move
    --german targeting
    --resolve battles one by one and get results
    --russian retreats? reduce hits by 1
    --german retreats? reduce hits by 1
    --german advaces
    --german reinforcements
end

function split(str, div)
    if (div=='') then 
        return false
    end

    local pos,arr = 0,{}

    -- for each divider found
    for st,sp in function() return string.find(str,div,pos,true) end do
        -- Attach chars left of current divider
        table.insert(arr,string.sub(str,pos,st-1)) 
        pos = sp + 1 -- Jump past current divider
    end
    
    -- Attach chars right of last divider
    table.insert(arr,string.sub(str,pos)) 
    return arr
end

--tab Tile
Tile = class()

function Tile:init(x, y, terrain, vp, feature, owner)
    self.x = x
    self.y = y
    self.terrain = terrain
    self.vp = vp
    self.feature = feature
    self.owner = owner
    self.rivern = 1
    self.riverne = 0
    self.rivere = 0
    self.riverse = riverse
    self.rivers = rivers
    self.riversw = riversw
    self.riverw = riverw
    self.rivernw = rivernw
    self.roadn = roadn
    self.roadne = roadne
    self.roade = roade
    self.roadse = roadse
    self.roads = roads
    self.roadsw = roadsw
    self.roadw = roadw
    self.roadnw = roadnw
    self.imagepath = "Dropbox:" .. terrain
    self.image = readImage(self.imagepath)
    self.width = 48
    self.height = 48
end

function Tile:draw()
    local pixelx1, pixelx2, pixely1, pixely2
    pixelx1 = ((self.x - 1) * self.width) + 1
    pixely1 = ((self.y - 1) * self.height) + 1

    --draw terrain
    sprite(self.image, ((self.x - 1) * self.width) + 1, ((self.y - 1) * self.height) + 1, self.width, self.height)

    --draw rivers
    --north rivers will need +48 to y values..
    if (self.rivern == 1) then
        strokeWidth(10)
        stroke(0, 0, 255, 255)
        line(pixelx1, pixely1+48, pixelx1+48, pixely1+48)        
    end

    
    --draw roads
    
    --draw features(city, bunker/fort)
    
    --draw vp's
    
end

function Tile:touched(touch)
    if touch.state == ENDED then
        if self:hit(vec2(touch.x, touch.y)) then
            print("touched tile: " ..self.x..","..self.y)
        end
    end
end

function Tile:hit(point)
    if point.x > (self.x * self.width - self.width/2) and
       point.x < (self.x * self.width + self.width/2) and
       point.y > (self.y * self.height - self.height/2) and
       point.y < (self.y * self.height + self.height/2) then
        return true
    end 
    
    return false
end


--tab Unit
Unit = class()

function Unit:init(x, y, unittype, owner, health)
    self.x = x
    self.y = y
    self.type = unittype
    self.owner = owner
    self.health = 2
    self.combatid = 0  --this will be the unit id of te defender
    self.imgpath = "Dropbox:"..owner.. unittype
    self.image = readImage(self.imgpath)
    self.width = 32
    self.height = 32
end

function Unit:draw()
    sprite(self.image, ((self.x - 1) * 48) + 9, ((self.y - 1) * 48) + 9, self.width, self.height)
end

function Unit:touched(touch)
    if touch.state == ENDED then
        if self:hit(vec2(touch.x, touch.y)) then
            print("touched unit: " ..self.x..","..self.y)
        end
    end
end

function Unit:hit(point)
    if point.x > (self.x * 48 - 48 + (48 - self.width)/2) and
       point.x < (self.x * 48 - (48 - self.width)/2) and
       point.y > (self.y * 48 - 48 + (48 - self.height)/2) and
       point.y < (self.y * 48 - (48 - self.height)/2) then
    return true
    end        
    return false
end

Please remember to “fence” your code:

~~~
like this
~~~

I’ve done it for you in the above post.

Format of code is off, is there tags to wrap around it? I can then edit if so.

oh ty

Without having the graphics, it makes it hard to run. I would say it isn’t a line error. Try changing the order you draw things and see how that affects things. Maybe that will give you an idea.

@Gib, you need to draw the lines above everything else to avoid this

I thought I was since that is the last thing done in the tile draw method. But if you also notice that I draw the square grid first in Map:draw() and it is not having any of the issues. It appears to be limited to the short line segmenets for the rivers. I guess if I have to I can create the graphics for the vertical, horizontal and corner riversides instead but I would like to know why codea is doing this.

I’ll try playing around some more, thanks for your eyes on this guys!

@Gib, Here’s what I think is happening (i haven’t looked at the code, sorry): you draw it on top of the tile, but then you draw another tile on top of that one which covers part of the line. You need to seperate the methods for drawing the tile and drawing the line, and call all of the draw tile methods, then all of the draw line methods. That should work

I see it now, yes, I will change and try again.

Thanks Jak!