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 8418913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:27:37+00:00 2026-06-10T02:27:37+00:00

I am writing a user interface to determine accuracies of click on an object.

  • 0

I am writing a user interface to determine accuracies of click on an object. Saw KineticJS and thought that would be a great tool to use.

I have created a simple stage with a circle in it. I am trying to draw a cross on the point someone clicks within the circle. I have found that the point that is drawn is offset to the bottom right of the cursor icon on screen. Also I am not sure why I cant seem to clear the area I draw some text to display the mouse co-ordinates. At the moment I get this weird overlaying of text on the same place.

Appreciate any input / suggestions.

Thanks.

index.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <script type="text/javascript" src="./assets/js/kineticjs/kinetic-v3.10.5.js"></script>

    <script type="text/javascript" src="./assets/js/pointingRender/pointingrender.js"></script> 

    <script type="text/javascript">
        $(document).ready(function(){
            initRender();
        });
    </script>

    <title>Pointing Devices User Interface</title>
</head>
<body>

<div id="container">
    <div id="mouseposition"></div>
</div>
</body>
</html>

pointingrender.js:

function initRender() {

    var stage = new Kinetic.Stage({
        container:"container",
        width:1920,
        height:1080
    });

    var layer = new Kinetic.Layer();

    var circle = new Kinetic.Circle({
        x:150,
        y:stage.getHeight() / 2,
        radius:70,
        fill:"red",
        stroke:"black",
        strokeWidth:4
    });


    var oval = new Kinetic.Ellipse({
        x:400,
        y:stage.getHeight() / 2,
        radius:{
            x:100,
            y:50
        },
        fill:"yellow",
        stroke:"black",
        strokeWidth:4,
        draggable:true
    });

    oval.on("mouseover", function () {
        document.body.style.cursor = "pointer";
    });
    oval.on("mouseout", function () {
        document.body.style.cursor = "default";
    });

    circle.on("mousedown", function(evt){

        var x = evt.clientX;
        var y = evt.clientY;
        var crossHorizontal = new Kinetic.Line({
                  points: [x-5, y, x+5, y],
                  stroke: "black",
                  strokeWidth: 1
                });
        var crossVertical = new Kinetic.Line({
                          points: [x, y-5, x, y+5],
                          stroke: "black",
                          strokeWidth: 1
                        });

        var anotherlayer = new Kinetic.Layer();

        anotherlayer.add(crossHorizontal);
        anotherlayer.add(crossVertical);
        stage.add(anotherlayer);
    });

    // add the shapes to the layer
    layer.add(circle);
    layer.add(oval);

    // add the layer to the stage
    stage.add(layer);

    var canvas = layer.getCanvas();
        var context = canvas.getContext('2d');
    var theDiv = document.getElementById('container');

        theDiv.addEventListener('mousemove', function (evt) {
            var mousePos = getMousePos(theDiv, evt);
            var message = "Mouse position: " + mousePos.x + "," + mousePos.y;
            writeMessage(canvas, message);

        }, false);
}

function writeMessage(canvas, message) {
    var context = canvas.getContext('2d');
    context.clearRect(0, 0, canvas.width, canvas.height);
    context.font = '18pt Calibri';
    context.fillStyle = 'black';
    context.fillText(message, 10, 25);
}



function getMousePos(canvas, evt) {
    var rect = canvas.getBoundingClientRect();

    // return relative mouse position
    var mouseX = evt.clientX ;
    var mouseY = evt.clientY ;
    return {
        x:mouseX,
        y:mouseY
    };
}
  • 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-10T02:27:38+00:00Added an answer on June 10, 2026 at 2:27 am

    Add “var messagelayer = new Kinetic.Layer(); for display Message Layer and add “canvas.clear();” in writeMessage Function for clear message.

    function initRender() {
    
        var stage = new Kinetic.Stage({
            container:"container",
            width:500,
            height:600
        });
    
        var layer = new Kinetic.Layer();
        var messagelayer = new Kinetic.Layer();
    
        var circle = new Kinetic.Circle({
            x:150,
            y:stage.getHeight() / 2,
            radius:70,
            fill:"red",
            stroke:"black",
            strokeWidth:4
        });
    
    
        var oval = new Kinetic.Ellipse({
            x:400,
            y:stage.getHeight() / 2,
            radius:{
                x:100,
                y:50
            },
            fill:"yellow",
            stroke:"black",
            strokeWidth:4,
            draggable:true
        });
    
        oval.on("mouseover", function () {
            document.body.style.cursor = "pointer";
        });
        oval.on("mouseout", function () {
            document.body.style.cursor = "default";
        });
    
        circle.on("mousedown", function(evt){
    
            var x = evt.clientX;
            var y = evt.clientY;
            var crossHorizontal = new Kinetic.Line({
                      points: [x-5, y, x+5, y],
                      stroke: "black",
                      strokeWidth: 1
                    });
            var crossVertical = new Kinetic.Line({
                              points: [x, y-5, x, y+5],
                              stroke: "black",
                              strokeWidth: 1
                            });
    
            var anotherlayer = new Kinetic.Layer();
    
            anotherlayer.add(crossHorizontal);
            anotherlayer.add(crossVertical);
            stage.add(anotherlayer);
        });
    
        // add the shapes to the layer
        layer.add(circle);
        layer.add(oval);
    
        // add the layer to the stage
        stage.add(layer);
        stage.add(messagelayer);
    
        var canvas = messagelayer.getCanvas();
            var context = canvas.getContext('2d');
        var theDiv = document.getElementById('container');
    
            theDiv.addEventListener('mousemove', function (evt) {
                var mousePos = getMousePos(theDiv, evt);
                var message = "Mouse position: " + mousePos.x + "," + mousePos.y;
                writeMessage(canvas, message);
    
            }, false);
    }
    
    function writeMessage(canvas, message) {
        var context = canvas.getContext('2d');
        canvas.clear();
        context.clearRect(0, 0, canvas.width, canvas.height);
        context.font = '18pt Calibri';
        context.fillStyle = 'black';
    
        context.fillText(message, 10, 25);
    }
    
    
    
    function getMousePos(canvas, evt) {
        var rect = canvas.getBoundingClientRect();
    
        // return relative mouse position
        var mouseX = evt.clientX ;
        var mouseY = evt.clientY ;
        return {
            x:mouseX,
            y:mouseY
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Web application that has a user interface for editing data.
I'm vb.net programmer. I would like to start writing unit & user interface test
I am writing a Web application that has a user interface for editing documents.
I'm writing a user interface with that allows a user to upload a set
My first question =). I'm writing a video game with a user interface written
I'm writing a tool which enables a user to interact with a bit of
I'm writing a class interface that needs to return references to binary files. Typically
I'm writing a graphical user interface to plot data on a xy-axis. It's written
When writing Cocoa apps, I do the majority of the user interface layout programmatically.
I've been writing my user interface directly instead of using the Qt UI design

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.