How do I specify mouse position over DrawingCanvas?

0 favourites
  • 6 posts
  • I'm making a rgb color eyedropper tool.

    The workflow is as follows:

    1. Have a picture in the form of a sprite.
    2. Set DrawingCanvas size and position to that of the sprite.
    3. Paste picture into the DrawingCanvas.
    4. Save snapshot of the DrawingCanvas.
    5. When ready, on mouse click I do "snapshotRedAt(mouse.x,mouse.y)

    That returns nothing when I click on the canvas, yet gives some readings when clicking outside the canvas which probably means that the coordinates for snapshotRedAt need to be relative?

    How do I then provide mouse coordinates for snapshotRedAt correctly in order to read pixel at that precise spot (independently of where the canvas is located in the layout?)


  • Try this:


    Also, check out this demo I made some time ago:

  • Thanks dop2000, that seems to be working.

    It still however only reads pixels in a fragment of the canvas. Upon logging things to the console it seems that for some reason the snapshot has different dimensions than the DrawingCanvas?

    //dimensions of sprite and canvas after pasting sprite (x and y)
    Dimensions of picture:768 511
    dimensions of DrawingCanvas: 768 511
    //dimensions of snapshot (inside "on snapshot")
    snapshot width: 339 snapshot height:226

    Any idea why would that happen?

  • Yeah, snapshot dimensions may be different, you need to take this into account:

    So I'm guessing you need (mouse.x-DrawingCanvas.BBoxLeft)/DrawingCanvas.PixelScale

    or possibly multiply :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yeah I ended up dividing by relation between DrawingCanvas width and Snapshot width which gets the proportions in order (got that from your capx)... but that's such a random problem to have o_O.


  • Be aware, that when the window size changes (in "On resolution change" event), you might need to redraw the canvas and regenerate the snapshot.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)