[SOLVED] How do I find the color of a position on a drawing canvas?

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
Color all tiles with the same color in 22 moves or less!
  • I know that this may sound trivial but I've been trying everything and it will not work for some reason. My goal is to make it so clicking on a mostly blue tile sets the text to "Allied nation" and clicking on a mostly red tile sets it to "Enemy nation."

    I think that a solution to this woudl require someone to look at the code themselves, so here is a link: https://drive.google.com/file/d/1sXZBJ0OCJQ11ka5YeNRmlA601PMR1xI0/view?usp=sharing

    It's only a prototype so there isn't much to look through.

    Tagged:

  • Main issue I'm seeing is you're not reading the pixel from the right spot. The snapshot size won't be the same size as the drawingCanvas unless the window isn't resized or if the drawing canvas' resolution mode is set to fixed, and the resolution is the same size as the canvas.

    Anyways, a fix would be to convert the coordinates. Instead of

    x = Mouse.x
    y = mouse.y

    use:

    x = Mouse.X*DrawingCanvas.SnapshotWidth/DrawingCanvas.Width
    y = Mouse.Y*DrawingCanvas.SnapshotHeight/DrawingCanvas.Height

    or if the drawing canvas isn't positioned at the top left of the layout:

    x = (Mouse.X-DrawingCanvas.BBoxLeft)*DrawingCanvas.SnapshotWidth/DrawingCanvas.Width
    y = (Mouse.Y-DrawingCanvas.BboxTop)*DrawingCanvas.SnapshotHeight/DrawingCanvas.Height

    dropbox.com/scl/fi/c9zekz1ru5pzw6u26mxon/read_pixels.c3p

    EDIT:

    Looks like these three expressions are approximately the same. So you could just divide the mouse position by the pixelScale. The fact that all three aren't all the same is another c3 issue but shouldn't matter too much.

    DrawingCanvas.SnapshotWidth/DrawingCanvas.Width

    DrawingCanvas.SnapshotHieght/DrawingCanvas.Height

    1/DrawingCanvas.PixelScale

    Edit2:

    If you manually set the fixed resolution mode size, then don't use pixelScale.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Main issue I'm seeing is you're not reading the pixel from the right spot. The snapshot size won't be the same size as the drawingCanvas unless the window isn't resized or if the drawing canvas' resolution mode is set to fixed, and the resolution is the same size as the canvas.

    Anyways, a fix would be to convert the coordinates. Instead of

    x = Mouse.x
    y = mouse.y

    use:

    x = Mouse.X*DrawingCanvas.SnapshotWidth/DrawingCanvas.Width
    y = Mouse.Y*DrawingCanvas.SnapshotHeight/DrawingCanvas.Height

    or if the drawing canvas isn't positioned at the top left of the layout:

    x = (Mouse.X-DrawingCanvas.BBoxLeft)*DrawingCanvas.SnapshotWidth/DrawingCanvas.Width
    y = (Mouse.Y-DrawingCanvas.BboxTop)*DrawingCanvas.SnapshotHeight/DrawingCanvas.Height

    https://www.dropbox.com/scl/fi/c9zekz1ru5pzw6u26mxon/read_pixels.c3p?rlkey=haodeqfz3vknri1qz8db4c5bm&st=b0zkb50o

    EDIT:

    Looks like these three expressions are approximately the same. So you could just divide the mouse position by the pixelScale. The fact that all three aren't all the same is another c3 issue but shouldn't matter too much.

    DrawingCanvas.SnapshotWidth/DrawingCanvas.Width

    DrawingCanvas.SnapshotHieght/DrawingCanvas.Height

    1/DrawingCanvas.PixelScale

    Edit2:

    If you manually set the fixed resolution mode size, then don't use pixelScale.

    Works like a charm, thanks!

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