How to create a new line while touching and dragging on the screen?

Any ideas?

I figured it out myself. Need to give a little pressure on the engine before asking such silly question.

local left = display.screenOriginX

local right = display.screenOriginY

local w = display.contentWidth

local h = display.contentHeight

rect = display.newRect(left, right, w, h)

rect.anchorX = 0

rect.anchorY = 0

rect.alpha = 0

rect.isHitTestable = true

function rect:touch(event)

    local phase = event.phase

    if phase == “began” then

        display.getCurrentStage():setFocus(self)

        self.beginX = event.x

        self.beginY = event.y

    elseif phase == “moved” then

        if event.y > self.beginY or event.y < self.beginY then

            local line = display.newLine(self.beginX, self.beginY, self.beginX, event.y)

            line.strokeWidth = 2

            line:setStrokeColor(1, 0, 0)

        – To make sure we create a straight vertical line

        elseif event.x > self.beginX or event.x < self.beginX then

            local line = display.newLine(self.beginX, self.beginY, event.x, self.beginY)

            line.strokeWidth = 2

            line:setStrokeColor(1, 0, 0)

 

        – To make sure we create a straight horizontal line

        end

    elseif phase == “ended” or phase == “cancelled” then

        display.getCurrentStage():setFocus(nil)

    end

end

rect:addEventListener(“touch”)

I figured it out myself. Need to give a little pressure on the engine before asking such silly question.

local left = display.screenOriginX

local right = display.screenOriginY

local w = display.contentWidth

local h = display.contentHeight

rect = display.newRect(left, right, w, h)

rect.anchorX = 0

rect.anchorY = 0

rect.alpha = 0

rect.isHitTestable = true

function rect:touch(event)

    local phase = event.phase

    if phase == “began” then

        display.getCurrentStage():setFocus(self)

        self.beginX = event.x

        self.beginY = event.y

    elseif phase == “moved” then

        if event.y > self.beginY or event.y < self.beginY then

            local line = display.newLine(self.beginX, self.beginY, self.beginX, event.y)

            line.strokeWidth = 2

            line:setStrokeColor(1, 0, 0)

        – To make sure we create a straight vertical line

        elseif event.x > self.beginX or event.x < self.beginX then

            local line = display.newLine(self.beginX, self.beginY, event.x, self.beginY)

            line.strokeWidth = 2

            line:setStrokeColor(1, 0, 0)

 

        – To make sure we create a straight horizontal line

        end

    elseif phase == “ended” or phase == “cancelled” then

        display.getCurrentStage():setFocus(nil)

    end

end

rect:addEventListener(“touch”)