How do I check the transparent pixels?

Not favoritedFavorited Favorited 0 favourites
  • 2 posts
From the Asset Store
Vintage steam pixels for your UI! 125 unique assets in a single pack!
  • Hi guys, please help.

    How is it possible to check the transparency of the touched area (Touch.X Touch.y) ?

    Shortly, i need to ignore the transparent area of the sprite and make it touchable only at painted pixels.

    Trying to do it with the drawing canvas ( DrawingCanvas.Snapshotat(x,y), but no luck.

    Setting up the collision polygons is not really an option, since there will be a lot of images.

    Thanks!

    Mak

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • To check for transparent pixels the general steps would be:

    Position a drawing canvas so it covers a sprite
    Paste the sprite onto the canvas
    Wait
    Snapshot canvas
    Wait
    Then read alpha at touch.x-canvas.bboxleft, touch.y-canvas.bboxtop

    There are two waits so it’s not something that will complete fast. So if you can snapshot the canvas less often then you’d only need to check the alpha expression. But that depends on what your game allows.

    In theory you could take all the sprite images and put their pixel alphas into arrays at the start of the game. Then it would be fast to access and you’d just need some make to convert a touch position to where on a transformed sprite to read the array from. This will be slow up front but instant after. But also consider having to set this up to begin with.

    Also consider that a touch won’t be pinpoint accurate so you can get away with an approximate collision polygon.

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