image tracking the cursor in main_menu screen[solved]

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
User avatar
SONTSE
Regular
Posts: 95
Joined: Sun Nov 24, 2013 10:49 pm
Completed: 8 VN's so far
Contact:

image tracking the cursor in main_menu screen[solved]

#1 Post by SONTSE » Sun Sep 21, 2014 10:30 am

so basically i need a image within a main_menu screen
that will update it's location according to my mouse pointer location.
lets assume it should stick to mouse pointer without being a mouse pointer,
or it should act as mirror projection of the cursor.
If i get these examples i will be able to adapt it for my needs.

For now i cannot figure out how to add an image with variable location
and how to repeatedly update this image.

What i can is locate my cursor coordinates
and make desirable image using an SpriteManager() example from docs but i cannot figure out how to add this to a screen.

Many thanks if you can help! Thanks anyway for bothering n__n
Last edited by SONTSE on Sun Sep 21, 2014 2:55 pm, edited 1 time in total.
Look! It's moving. It's alive. It's alive... IT'S ALIVE! Oh, in the name of God! Now I know what it feels like to be God!(@Henry_Frankenstein. Sums up my coding style)

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: image tracking the cursor in main_menu screen

#2 Post by PyTom » Sun Sep 21, 2014 12:02 pm

CDD time! When you can't figure out how to do something, use a CDD.

Code: Select all

init python:

    class TrackCursor(renpy.Displayable):

        def __init__(self, child):

            super(TrackCursor, self).__init__()

            self.child = renpy.displayable(child)

            self.x = None
            self.y = None

        def render(self, width, height, st, at):

            rv = renpy.Render(width, height)

            if self.x is not None:
                cr = renpy.render(self.child, width, height, st, at)
                cw, ch = cr.get_size()
                rv.blit(cr, (self.x - cw / 2, self.y - ch / 2))

            return rv

        def event(self, ev, x, y, st):

            if (x != self.x) or (y != self.y):
                self.x = x
                self.y = y
                renpy.redraw(self, 0)
Then add it to the screen with:

Code: Select all

    add TrackCursor("target1.png")
If people have questions, just ask - I want to get more CDD info out there.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
SONTSE
Regular
Posts: 95
Joined: Sun Nov 24, 2013 10:49 pm
Completed: 8 VN's so far
Contact:

Re: image tracking the cursor in main_menu screen[solved]

#3 Post by SONTSE » Sun Sep 21, 2014 3:04 pm

... and needless to say it works like a charm XD
Thank you, PyTom! You as brilliant as ever!

i think I'll need to dig on some RenPy/python manuals so i can understand what exactly does this code... after i overcome a shock seeing it ^^'''' well. anyway i already found how to tweak it for my needs, so its okay for now.

Thanks again!
Look! It's moving. It's alive. It's alive... IT'S ALIVE! Oh, in the name of God! Now I know what it feels like to be God!(@Henry_Frankenstein. Sums up my coding style)

Post Reply

Who is online

Users browsing this forum: Google [Bot], zyric