Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Exact pixel hit detection #142

Open
Open

Description

@ryanjarvis

It appears that an Actor is notified if a mouse event affects it by checking to see if the mouse event coordinates are contained within the bounding box of the Actor only.

I would like to see support for determining if you clicked on the actual pixels that the Actor paints on the canvas.

I am wondering how difficult it would be to implement this. I researched two approaches. First is using another canvas as a hit canvas described here: http://tschaub.net/blog/2011/03/31/canvas-hit-detection.html Not sure if that approach makes sense in CAAT's overall architecture. Second, is checking to see if a point is in the path of an Actor when it is drawn using isPointinPath described here: http://digitalarts.bgsu.edu/faculty/bonniem/Spring11/artc4330_1/notes/notes26.html If Actors are redrawn everytime the system checks to see if a mouse interaction occurred, I am thinking this might be doable.

Activity

  1. sntran commented on May 16, 2013

    @sntran

    I would second this. It may be easier with Box2D since you can loop through the fixture and check for mouse location is within any.

  2. hyperandroid commented on May 17, 2013

    @hyperandroid
    Owner

    Are you referring to actors that contain images, or to a general shape ?
    The first thing, is definitely straighforward. Just extract the image's
    alpha channel, and compare the alpha value at x,y coordinate values
    supplied to every mouse/click functions.

    The other one, is certainly trickier. CAAT has two different stages per
    frame:

    transformation and paint.

    what you pretend is to know at input bubling time, whether the mouse is
    inside what an actor painted. Definitely isPointInPath exists in the canvas
    rendering context (ctx). But CAAT uses its own path implementation. If you
    anyway use the ctx to draw your actor, you could definitely call
    ctx.isPointInPath to know whether it lies inside/outside.

    What is your exact use case ?

    • i

    2013/5/16 Son Tran-Nguyen notifications@github.com

    I would second this. It may be easier with Box2D since you can loop
    through the fixture and check for mouse location is within any.

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/142#issuecomment-18034107
    .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions