count number of transparent pixels in sprite

This forum is currently in read-only mode.
  • need number of pixels that are not transparent as a value. with this i can create is totally covered event by using another 1 pixel sprite in a container to scan across the top-left to bottom right of main sprite when it overlaps both the main sprite and other sprite 1 is added to variable. when it reaches the end if untransparent pixels of sprite match variable it means its completely covered.

  • You can do this already, but its very slow.

    Image manipulator copy from sprite

    For x = 1 to sprite.width

    for y =1 to sprite.height

    System: ImageManipulator GetAlpha(LoopIndex("x"), LoopIndex("y")) Equal to 0

    >sprite add 1 to sprite.privatevariable

    Then if you want not transparent just use greater than 0, but beware of semi transparencies.

  • What on earth do you need this for? It seems a very obscure case to spend programming time on.

  • I did something similar with my terrain generator, but that was an app not a game.

    It might sound like a good idea, but per pixel operations will always be way to slow for regular events.

    I mean its doable, for something like on the start or load of a layout, if you want to create or save some data for use later.

  • quote. what on earth would you do with it

    quote. can make totally covered event

    there are many things you can do with completely covered events. especially for a.i. its been asked b4

    at newt. yeah you could set it up for your frames at startup and use value later. transparent or not transparent dont matter because if you got one you can get the other

    for speed on regular event i would go with setting it up to run when specify conditions are met probably with trigger once. normally you wouldn't want to scan px by px just like you wouldnt want while condition to run always

  • Occlusion query?

  • How would it help with a 'completely covered' event? It doesn't tell you where the transparent pixels are, just how many there are...

  • with a event that uses a 1px scanner sprite that scans each pixel of sprite checking for overlaps and counting them if amount overlapped = to number of px not transparent it is covered. you can get untransparent number by subtracting the width and height minus transparent or vice versa for getting transparent either value will do.

    by transparent i mean opacity or alpha = 0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • at newt. have you tried

    Image manipulator copy from sprite

    For x = 1 to sprite.width

    for y =1 to sprite.height

    System: ImageManipulator GetAlpha(LoopIndex("x"), LoopIndex("y")) Equal to 0

    sprite add 1 to sprite.privatevariable

    in new version. if you do and it works can you post cap. i dont want to report if its not bug. i tried on 2x2 sprite half transparent other color and variable goes to 4.

  • Yeah I'm getting some weird results, but I suspect its image editor related rather than imagmanipulator, but that's just another reason to use the function sparingly. Again per pixel operations are always going to be quirky especially when dealing with semi transparencies, not to mention other users hardware.

  • Again: Occlusion Query

    I believe it does this exact same thing... though it would have to be a plugin.

  • i think i have a possible solution. but im not at home to test it

    my break is just about over so i cant break it down into each little layer operation, but basically you make the object that must be checked as completely covered, and use the covering object as a mask,paste this to a canvas, and update collision mask, then check for a collision with the original unmasked sprite. if there is a collision, it is not fully covered.

  • Well its certainly simpler than getting coords for each pixel.

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