[SOLVED]Image Zoom From Center Doesn't Work

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
Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

[SOLVED]Image Zoom From Center Doesn't Work

#1 Post by Nero »

Hi, this might be a simple problem to solve but I'm having some trouble. Basically I want my picture to be zoomed out from the CENTER of its position not from the LEFT upper corner as it is default. I was searching some documentation but it seems like it doesn't work or maybe I'm using it incorrectly?

Code: Select all

image x:
    "x.png"
    truecenter
    zoom 1.0
    ease 3.0 zoom 1.5
Last edited by Nero on Tue Jun 16, 2020 12:59 pm, edited 1 time in total.

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Image Zoom From Center Doesn't Work

#2 Post by Per K Grok »

Nero wrote: Mon Jun 15, 2020 11:29 pm Hi, this might be a simple problem to solve but I'm having some trouble. Basically I want my picture to be zoomed out from the CENTER of its position not from the LEFT upper corner as it is default. I was searching some documentation but it seems like it doesn't work or maybe I'm using it incorrectly?

Code: Select all

image x:
    "x.png"
    truecenter
    zoom 1.0
    ease 3.0 zoom 1.5
One way of doing this is to use xpos and ypos to position the image and as you zoom the images size you move the xpos and ypos at the same time using the zoom value.

In this example I have a sprite with the size 48x90. Since you want to have the position fixed to the center we will use half of those values, 24 and 45

Code: Select all


    show bub15:
        pos (200-24 ,200-45)     ## center positioned at 200, 200
        zoom 1.0
        ease 3.0 zoom 1.5 xpos int(200 - (24*1.5)) ypos int(200 - (45*1.5))    ## center always positioned at 200, 200  using half of the sprites width and height at any time during the movement.   Since a position in pixels is a whole number I transform the number for xpos and ypos from a float to an integer.



User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Image Zoom From Center Doesn't Work

#3 Post by Remix »

Hmmm, works fine here.

Using truecenter sets the align property to (0.5,0.5) which in turn sets both anchor and pos to the same value.
Having the image anchored at 0.5,0.5 is exactly what you want.

What syntax are you using to show it?

Code: Select all

label start:
    show x
    "..."
The only way I could see this failing is if you were showing it inside another container that was aligned differently... such as a frame in a screen....

Sub-note: I would advise adding subpixel True to your transform (for any zoom or rotate)
Frameworks & Scriptlets:

Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: Image Zoom From Center Doesn't Work

#4 Post by Nero »

Both of your solutions worked fine guys.

Per K Grok your case also works now that I fixed the frame problem.

Remix as you said problem was that it was inside of a frame but I managed to make it work with some tweaking.

Thanks!

Post Reply

Who is online

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