Graphical bug[SOLVED]

Hello all,
Today I was working on a quick physics sandbox type thing. Double tap and drag to create rectangles. The weird thing happened when I was trying to put a stroke on the rectangles, it just filled the entire shape with that color no matter what I set the stroke to be. Also, the shapes wouldn’t even show up unless I called noStroke(). I tried moving the addObj class into a new project and it worked, so I figured it had to be something with the graphical code somewhere else. I then tried commenting out everything else having to do with graphics, but to no avail. Does anyone have any idea what is going on? Code:


--# addObj
addObj = class()

function addObj:init(initPos,endPos,mode)
    -- you can accept and set parameters here
    self.initPos,self.endPos,self.mode = initPos, endPos, mode
    self.w,self.h = self.endPos.x-self.initPos.x,self.endPos.y-self.initPos.y
    if self.mode == POLYGON then
        self.body = physics.body(POLYGON,vec2(self.w/-2,self.h/-2),vec2(self.w/2,self.h/-2),vec2(self.w/2,self.h/2),vec2(self.w/-2,self.h/2))
        self.body.x = (self.initPos.x+self.endPos.x)/2
        self.body.y = (self.initPos.y+self.endPos.y)/2
    end
end

function addObj:draw()
    -- Codea does not automatically call this method
    pushStyle()
    fill(255,0,255)
    strokeWidth(10)
    if self.mode == POLYGON then
        pushMatrix()
        translate(self.body.x,self.body.y)
        rotate(self.body.angle)
        rect(self.w/-2,self.h/-2,self.w,self.h)
        popMatrix()
    end
    popStyle()
end

function addObj:touched(touch)
    -- Codea does not automatically call this method
end

--# levelHandler
levelHandler = class()

function levelHandler:init()
    -- you can accept and set parameters here
    PHYSWIDTH = 3*WIDTH/4
    self.c = physics.body(POLYGON, vec2(0,0),vec2(PHYSWIDTH, 0), vec2(PHYSWIDTH,100),vec2(0,100))
    self.c.type = STATIC
    self.shapeState = POLYGON
end

function levelHandler:draw()
    -- Codea does not automatically call this method
    noSmooth()
    for i,v in pairs(objects) do
        v:draw()
    end
    fill(0,255,0)
    rect(0,0,PHYSWIDTH,100)
    fill(186, 186, 186, 255)
    rect(PHYSWIDTH, 0, WIDTH-PHYSWIDTH, HEIGHT)
end

function levelHandler:touched(touch)
    -- Codea does not automatically call this method
    if not self.tId and touch.tapCount == 2 then
        self.tId = touch.id
        self.initPos = vec2(touch.x,touch.y)
    end
    if self.tId == touch.id and touch.state == ENDED then
        table.insert(objects, addObj(self.initPos, vec2(touch.x,touch.y), self.shapeState))
        self.tId = nil
        self.initPos = nil
    end
end
--# Main
-- Physics sandbox

-- Use this function to perform your initial setup
function setup()
    l = levelHandler()
    objects = {}
    touches = {}
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

    -- Do your drawing here
    l:draw()
end

function touched(t)
    l:touched(t)
end

@TheSolderKing Are you trying to draw just the outline of a rectangle. noFill() is used, but that doesn’t seem to work on your rectangles. But if I add just a normal rectangle in addObj:draw it does draw that rectangle not filled.

@TheSolderKing I think your problem is with self.w and self.h in addObj:draw(). Those values are negative depending on how you swipe. You need to always make them positive.

EDIT: Nevermind, that was indeed the problem! Thanks @dave1707!

I suppose that teaches me to always use meshes instead. Thanks again!