[solved]how can I calculate xalign using xpos and xsize?

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
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

[solved]how can I calculate xalign using xpos and xsize?

#1 Post by Kia »

as you know the "xanchor" changes with "xalign", this made me wonder what's the correct formula for calculating "xalign" of a dragged child using available information:
drag[0].x
drag[0].w
and config.screen_width
Last edited by Kia on Tue Jan 22, 2019 2:35 am, edited 1 time in total.

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: how can I calculate xalign using xpos and xsize?

#2 Post by DragoonHP »

Code: Select all

cal_xalign_value = drag[0].x/config.screen_width
This should give you an xalign value in respect to the entire screen.

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: how can I calculate xalign using xpos and xsize?

#3 Post by Kia »

DragoonHP wrote: Mon Jan 21, 2019 11:53 am

Code: Select all

cal_xalign_value = drag[0].x/config.screen_width
This should give you an xalign value in respect to the entire screen.
unfortunately this doesn't take into account the width of the drag's child and the change in the xanchor when drag is moved towards the left side of screen. only works if the width of child is zero.

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: how can I calculate xalign using xpos and xsize?

#4 Post by DragoonHP »

Can you tell me what you are trying to do? I'm not sure how width of a child affects xalign

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: how can I calculate xalign using xpos and xsize?

#5 Post by Per K Grok »

Kia wrote: Mon Jan 21, 2019 9:22 am what's the correct formula for calculating "xalign" of a dragged child using available information:
I think this should work

xalign = xpos / (screenwidth - xsize)

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: how can I calculate xalign using xpos and xsize?

#6 Post by Kia »

Per K Grok wrote: Tue Jan 22, 2019 1:58 am I think this should work

xalign = xpos / (screenwidth - xsize)
thank you ^_^
it's was as simple as putting two and two together, yet I failed to see it for hours of trial and error. :oops:

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: how can I calculate xalign using xpos and xsize?

#7 Post by Kia »

DragoonHP wrote: Mon Jan 21, 2019 11:41 pm Can you tell me what you are trying to do? I'm not sure how width of a child affects xalign
while using xalign, it's necessary that the anchor point of the child to be aligned along the child's width. for example:
xalign 1.0 causes the xanchor to be set to 1.0 and the child to be aligned by it's right side instead of the usual left side.
and xalign 0.5 sets xanchor to 0.5 and align the child by it's center to keep the object at the center.
that's why we have to consider the child's width in calculation, DragoonHP gave me the solution.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]