Page 1 of 1

image tracking the cursor in main_menu screen[solved]

Posted: Sun Sep 21, 2014 10:30 am
by SONTSE
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

Re: image tracking the cursor in main_menu screen

Posted: Sun Sep 21, 2014 12:02 pm
by PyTom
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.

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

Posted: Sun Sep 21, 2014 3:04 pm
by SONTSE
... 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!