Detecting images on contact

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Doeny
Regular
Posts: 26
Joined: Wed Sep 07, 2022 8:28 pm
Contact:

Detecting images on contact

#1 Post by Doeny » Sat Oct 29, 2022 7:27 pm

Is there a way to check if an image touches other image and if possiple make it a function?

User avatar
barsunduk
Newbie
Posts: 18
Joined: Fri Jul 18, 2014 1:06 pm
Completed: «Crystal City», «Mega City», «Kilmonger», «Neuronaut», «Love, Death & Veggies», «Arrow Tourney», «Big Red Hood: Halloween», «Succubus Throne»
Projects: «Swordsman Tourney», «This Tiny Galaxy»
Organization: 7DOTS
itch: 7dots
Contact:

Re: Detecting images on contact

#2 Post by barsunduk » Sun Oct 30, 2022 6:52 am

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

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]