Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8563289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:55:38+00:00 2026-06-11T16:55:38+00:00

I’m fairly new to JavaScript and been fiddling around with HTML5 element. The thing

  • 0

I’m fairly new to JavaScript and been fiddling around with HTML5 element.

The thing is that I’m now using a library to help simplify the use of the canvas on a multitude of devices, including mobile, but I have now a question that is bugging me since it appears so simple yet I’m unable to find a solution. I do believe this might be a newbie mistake but here is the deal:

I have these 2 functions:

function drawLine(sX, sY, eX, eY) {
    ctx.beginPath()
    ctx.moveTo(sX, sY);
    ctx.lineTo(eX, eY);
    ctx.stroke();
    ctx.closePath();
    return { x: eX, y: eY };
}

function canvas() {
    var canvas = new Canvas ('canvas', 0, function () {
        this.clear();
        this.setAutoResize(true);
    });

    canvas.canvasElement.width = window.innerWidth;
    canvas.canvasElement.height = window.innerHeight;

    canvas.onTouchStart = function(start) {
        var sX; var sY;
        return {sX: start.clientX, sY: start.clientY};
    }

    canvas.onTouchEnd = function (end) {
        var eX; var eY;
        return {eX: end.clientX, eY: end.clientY};
    }

    // canvas.onTouchMove = drawLine(sX, sY, eX, eY);
}

Not getting into too much detail, how will I be able to use the values returned by onTouchStart() and onTouchEnd() to pass the x,y positions into the drawLine function?

All I’m getting is values that are not defined and I’m really lost here..

UPDATE:

@Juan Mendes,

Thanks for your help, but that didn’t seem to work either.

For a better understanding of the “backside” code, here is an example of the touchstart thing:

this.canvasElement.addEventListener('touchstart', function(event) {
    var touchCount = event.changedTouches.length;
    var touches = [];
    var touch = null;

    for (var i = 0; i < touchCount; i++) {
        touch = event.changedTouches[i];

        var touchInfo = {
            pageX : touch.pageX,
            pageY : touch.pageY,
            clientX : touch.clientX,
            clientY : touch.clientY,
            screenX : touch.screenX,
            screenY : touch.screenY,
            target : touch.target,
            identifier : touch.identifier
        };

    self.onTouchStart(touchInfo, i, touchCount, event);

    touches.push(touchInfo);

    self.previousTouchInfo[touch.identifier] = touchInfo;
    }

    if (touchCount == 1) {
        touch = event.changedTouches[0];

        var x = touch.clientX;
        var y = touch.clientY;

        if (self.touchEmulatesMouse) {
            self.mouse.x = x;
            self.mouse.y = y;
            self.mouse.left = true;

            if (self.layerParent != null) {
                self.layerParent.onMouseDown(x, y, 0);
            }

        self.onMouseDown(x, y, 0);
        }
        } else {
            self.onMultiTouchStart(touches, event);
        }
    }, false);

/* A bit more down the library code */
/**
* Called at the start of every touch start (including when multiple touches occured)
*
* The info object contains the folloring info:
* - pageX - X coordinate relative to the full page (includes scrolling)
* - pageY - Y coordinate relative to the full page (includes scrolling)
* - clientX - X coordinate of touch relative to the viewport (excludes scroll offset)
* - clientY - Y coordinate of touch relative to the viewport (excludes scroll offset)
* - screenX - X coordinate relative to the screen
* - screenY - Y coordinate relative to the screen
*
* @param {object} info Touch info
* @param {integer} index Touch index
* @param {integer} count The total number of active touches
* @param {object} event The actual touch event
*/
onTouchStart: function(info, index, count, event) {},

And I also changed my code to reflect your help, a few changes and also tried using the touchInfo param like this:

function createCanvas() {
var canvas = new Canvas ('canvas', 0, function () {
    this.clear();
    this.setAutoResize(true);
});

var cWidth = canvas.canvasElement.width = window.innerWidth;
var cHeight = canvas.canvasElement.height = window.innerHeight;

var startPoint = null;

function fill() {
    canvas.fillStyle = "black";
    canvas.fillRect(0, 0, cWidth, cHeight);
    canvas.beginPath();
}

// Draw a line on the canvas from (s)tart to (e)nd
function drawLine(sX, sY, eX, eY) {
    canvas.beginPath()
    canvas.moveTo(sX, sY);
    canvas.lineTo(eX, eY);
    canvas.stroke();
    canvas.closePath();
    //return { x: eX, y: eY };
}

fill();

canvas.onTouchStart = function(start) {
    startPoint = {sX: this.clientX, sY: this.clientY};
}

canvas.onTouchEnd = function (end) {
    drawLine(startPoint.sX, startPoint.sY, this.clientX, this.clientY);
    // return {eX: end.clientX, eY: end.clientY};
}
}

Any help would be very appreciated. Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:55:39+00:00Added an answer on June 11, 2026 at 4:55 pm

    I finally managed to get around the problem. Turns out the library wasn’t properly ended (yet) and I was also misusing the functions without getting any arguments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.