Page 1 of 1

Detecting images on contact

Posted: Sat Oct 29, 2022 7:27 pm
by Doeny
Is there a way to check if an image touches other image and if possiple make it a function?

Re: Detecting images on contact

Posted: Sun Oct 30, 2022 6:52 am
by barsunduk
As far as I know, Renpy doesn't support collision. But for simple skeet shooting, I use the code for one point.

Code: Select all

init python:
    def get_opaque(img, x=None, y=None):
        rv = renpy.render(renpy.displayable(img), config.screen_width, config.screen_height, 0, 0)
        w, h = rv.get_size()
        w, h = int(w), int(h)
        if x is None:
            x = w - 1
        if y is None:
            y = h - 1
        return rv.is_pixel_opaque(x, y)

    def is_opaque(img, x=None, y=None, min_a=0):
        a = is_opaque(img, x, y)
        return a > min_a