Is there a way to cut a hole in another object?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hey guys, I'd like to achieve a similar effect to the 'Subtract' effect often used to create a light source around a character as described in this thread > Please login to see this link.

    But the difference is I want to be able to cut/mask a hole in a multi-colored object, not just a single colored background, is this at all possible? Any help or ideas would be greatly appreciated! :)

    Edited once, last by Gradius (May 4, 2016 at 12:36 PM).

  • Yore already doing it better than I can, which is make a giant black active object with a big hole in it and have it follow the guy around :)

    Weebish Mines, my retro Metroidvania!
    Please login to see this link.

  • There is an effect too that creates a hole in the active and you can also reposition the hole if needed. I'm using it in my game it might even be called "Hole.fx" i don't remember right now nor if it is included at default or part of a shader pack or something :D

  • Thanks guys, yeah I tried the "hole" shader, it's part of Looki's shader pack I think, but the problem was I couldn't figure out how to bind the holes position to my mouse pointer, which is what I need to do. Would you have any idea's how to do this?

  • that shader has a bunch of parameters: fS, fE, fX, fY, fRatio, fC, iInvert, iH, iV. No idea what most of them do, but I'd guess you'd want to look at fX and fY.

    Try something like:
    always
    -set effect parameter "fX" to xMouse
    -set effect parameter "fY" to yMouse

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

  • Hi Volnaiskra, thanks for the suggestion, unfortunately that was the first thing I tried but it didn't seem to work, the 'hole' effect just disappeared completely when I used that event, I'm not really sure what else I can try at this point...

  • Shaders don't use pixels as a unit of measurement - coordinates always range from 0 to 1.
    So for example, the object/layer to which the shader is applied, will always have an X coordinate of 0 at its left edge, and 1 at its right edge, regardless of how big it is, or where it is positioned on screen.
    Therefore, you need to offset the coordinates to account for position, and then scale the coordinates to account for size.

    X = (MouseX - ObjectX) / ObjectWidth
    Y = (MouseY - ObjectY) / ObjectWidth

  • Hey MuddyMole, thanks, your explanation makes perfect sense, but I still can't seem to implement it, I hate to be a pain but is there any chance someone could maybe upload a quick example mfa for me? I'm quite new to using shaders, so it's a little overwhelming...

  • Surface object is flexible enough to allow all sorts of different things like this, and it might be a tad more accessible to beginners. Shaders are likely to be the more efficient method but it depends on your application. If the performance of Surface is adequate in your game then there's nothing wrong with using it (unless you want to export to some platform that doesn't support it).

    If you do want to learn shaders, my suggestion is:

    1.) Find a very simple shader to use as a template.
    2.) Code a shader that just renders every pixel in the sprite as red.
    3.) Code a shader that uses the sprite's alpha mask, but colors all the pixels red.
    4.) Code a "health bar" shader that renders a sprite, but cuts off anything to the right of a given pixel value, which you feed in as a parameter.

    Once you've gone through this learning process, making a hole-cutting shader would be pretty easy. Just feed in an X, Y, and radius for the hole, then have each pixel test if dX*dX + dY * dY > radius * radius before they can be drawn.

    Please login to see this link. (Indie games and Fusion resources)
    For freelance inquiries please email admin at ultimatewalrus.com

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!