Zoom "on the fly"

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
herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

Zoom "on the fly"

#1 Post by herenvardo » Mon Dec 05, 2011 5:07 pm

I'll try to go straight to the point.

I have a chunk of code like this within one of my screens:

Code: Select all

            grid 3 2:
                area (62, 120, 900, 700)
                for c in charDesc.iterkeys():
                    imagebutton action SetScreenVariable('currSelection', c):
                        idle ("img/portrait.%s.png"%(c))
                        hover ("img/portrait.%s.png"%(c))
                        area (50, 25, 200, 300)
The 'portrait' images are 400px (wide) × 600px (high). As you may infer from the 'area' properties on the grid and the imagebuttons, I want to display those at half their size.
After trying that code, I have found out that the size provided by the "area" is not honored at all (the positioning is correct, but with the images displaying at double the intended size, the overlapping is horrible). Even if 'area' fails to zoom the image (rather understandable), I would have expected it to at least clip it to the given size.

I know I could use pre-scaled versions of the files for this; but both the "small" and "full-size" versions of these portraits are used only on this screen; so I'd prefer to re-use the same files and make my files easier to manage.

I googled around for an answer and the closest I got was this http://www.renpy.org/wiki/renpy/doc/ref ... tions/Zoom, which is marked as "Deprecated".
My "evil" side is more than willing to write a python function to get the job done and then call it from within the for loop (passing 'c' as an argument)... but before I walk the dark path,

is there a good renpyish way to zoom images on the fly? (within the definition of an imagebutton)
As you can notice, the interpolation is already ugly enough (the new-style [] syntax doesn't seem to work with a local variable :( ), so I hope I can keep the code as readable as possible.

On a side note: right now, the images don't change at all when hovered, I don't know yet if the final version will include "hovered" variants (it'll depend on available time). Is a zoom operation too costly? If so, it'd be good to know if there is a (sane enough) way to do the zoom in advance, and then use the pre-zoomed image, rather than doing things on the fly on every iteration.
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

User avatar
PyTom
Ren'Py Creator
Posts: 15454
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: Zoom "on the fly"

#2 Post by PyTom » Mon Dec 05, 2011 5:28 pm

Just use a transform:

Code: Select all

                    imagebutton action SetScreenVariable('currSelection', c):
                        idle Transform("img/portrait.%s.png" % c, zoom=.5)
                        hover Transform("img/portrait.%s.png" % c, zoom=.5)
                        area (50, 25, 200, 300)
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
herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

Re: Zoom "on the fly"

#3 Post by herenvardo » Mon Dec 05, 2011 7:15 pm

Yay! That looks "good" and "renpyish" enough, thanks.

Another function whose entry in the documentation has earned a slot in my bookmarks :D
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

Post Reply

Who is online

Users browsing this forum: Google [Bot]