help: magnifying glass *~*

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
rinyaba
Newbie
Posts: 4
Joined: Thu Dec 10, 2020 12:25 pm
Contact:

help: magnifying glass *~*

#1 Post by rinyaba » Wed May 04, 2022 10:15 am

Image
I have a concept I'm curious if possible to execute in renpy. I created the above image with Gimp as an example..
1.The renpy game displays a large amount of tiny font text
2. There is a magnifying glass PNG following the mouse cursor position.
3. Some code shows a magnified version of the text underneath the magnifying glass..

I looked at alpha masks, and speculated on CDD but I don't know how to write python. Does anyone have any pointers? If i just showed an enlarged image of the text, and somehow masked that with a mouse cursor image.. that enlarged layer would have to move at a different rate than the mouse cursor to accommodate for (I'm not sure what term to use)... parallax effect? hehe &~& T_T
thx for anyone who takes a sec.

rayminator
Miko-Class Veteran
Posts: 754
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: help: magnifying glass *~*

#2 Post by rayminator » Wed May 04, 2022 11:16 am

here is a couple of pointers:

start slow and don't rush

read the documentation on renpy
https://www.renpy.org/doc/html/

this is how I started using renpy
learn python
start on a small project (learn how to use default/define/jump/call/label and choices)
learn more python
start on a medium project (learn how to use screens and how to place them by using call screen and show screen)
learn even more python
start on a large project (learn how to use class/def and how to use them)

User avatar
ISAWHIM
Veteran
Posts: 302
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: help: magnifying glass *~*

#3 Post by ISAWHIM » Mon May 09, 2022 4:18 pm

I had a similar effect, using simple layers and masks. (It was for a hide and seek hunt, using a magnifying glass.)

The top layer would be the small font image, the bottom layer would be the 2x font image. The mask just pokes a hole through the top layer. (Maybe I did it reverse, so the mask was inverted and only showed the top layer as the hole?!?

The 2x image can just be a normal image-scale. (Again, it might be better to reverse the scale so the smaller one has 0.5 scale. This will retain the full pixel-detail of the "seemingly larger image", which is actually just normal sized, in relation to the smaller image.)

This was in the script.rpy

Code: Select all

init python:
    class TrackCursor(renpy.Displayable):
        def __init__(self, child, **kwargs):
            super(TrackCursor, self).__init__(**kwargs)
            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)


# The game starts here.

label start:
    show screen xray("full_pic1", "behind_pic2")
    "What are you looking for?"
    show screen xray("full_pic2", "behind_pic2")
    "Do you need better glasses?"

    # This ends the game
    return
This goes in screens.rpy

Code: Select all

################################################################################
## In-game screens
################################################################################

image lense = TrackCursor("lenses")
image rims = TrackCursor("glasses")
transform noalpha:
    alpha 0.0
screen xray(full_IMG, behind_IMG):
    add full_IMG
    add AlphaMask(behind_IMG, "lense")
    add "lense" at noalpha
    add "rims"
Images needed...
- full_pic1.jpg
- behind_pic1.jpg
- full_pic2.jpg
- behind_pic2.jpg
- lenses.png (The hole mask)
- glasses.png (The rim of the glasses)

NOTE: The "lenses" were the actual "mask-hole", which you see through. The "Rims" are the edges of the glasses, which shows over the mask-hole.

Your "behind_pic1.jpg" should be the 2x image, in this sample. Also note that both of my images were alpha images. So this should be transparent safe, over a solid background of other images in a scene. (It should only poke a hole through the full_pic, showing the behind_pic.)

P.S. Realize that your smaller image text has to be a bit away from the edge... The text will be 2x larger, but stationary. You would have to alter the position of the "behind" picture, with the cursor movement, by 2x on X and Y, to get a true magnifying effect.

Below is a quick sample image, directly from this source-code I use as my demo.
Image1.jpg
The attached lenses and rims images, just click with a mouse and "Save as..." and use a paint-program, or "open in new window", to see the transparent sections, which should be a bit more "grey" in a "new window". I didn't realize the forum uses a white background. The lenses in this sample are just "white".
Attachments
lenses.png
lenses.png So you can see where the transparent parts need to be.
lenses.png (1.92 KiB) Viewed 214 times
glasses.png
glasses.png So you can see where the transparent parts need to be.
glasses.png (2.21 KiB) Viewed 214 times

Post Reply

Who is online

Users browsing this forum: No registered users