How do I detect transparent pixels with javascript

0 favourites
  • 5 posts
From the Asset Store
Vintage steam pixels for your UI! 125 unique assets in a single pack!
  • As far as I know there's no built-in way in C2 to determine whether a user has clicked on a transparent area of a sprite.

    Is there a chance to insert a Browser.Exec.JS on the "On object clicked" event and capture the transparency value into a variable?

    I'm thinking I can then trigger the action I want only if the value in the variable is <255.

  • Could you explain in what way this would be useful?

    I know the canvas plugin by rojohound has the functionality to get rgbaAt any x,y

  • LittleStain

    I'm doing an application where several images are loaded in runtime and then put into animation frames of a single sprite.

    I then create instances of that sprite and set each one into a different animation frame. (Thus, i have a bunch of images on the canvas)

    Now, the collision polygon of each of these instances is its bounding box (can't change that on runtime).

    All I want to do, is when I click on one of them (on a transparent area), ignore the click, check if there's another sprite instance under the mouse pointer, and fire a click event on that one instead.

    Thanks for bringing into attention the canvas plugin. I'll give it a go!

    EDIT: Maybe this is a good place for a request. Ashley, how difficult would be to implement a feature (both in the editor and on runtime), where mouse events ignore completely transparent pixels on a sprite?

  • This kind of feature is difficult to support since it requires fetching pixel data from the GPU, which typically stalls the rendering pipeline and results in awful performance. So because of that if at all possible you should not even try to do this, and look for an alternative solution. For example perhaps there could be some way to use an existing sprite with a collision polygon that can be used to test collisions instead?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ashley

    Thanks a lot for the detailed reply! I truly understand now how difficult it is to support this feature. As an alternative, I have the option to display a list to select the sprites from and it seems that's the way I'm going to. Thanks again for your valuable time!

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