misplaced focus_mask
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.
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.
misplaced focus_mask
Hi,
In my game I created buttons to navigate from one place to an other (image1), which only appear when the mouse hovers over them (image2, see code). Problem is, the text I put in the overlay image is not always inside the area I want to be clickable, so I want to use focus masks (as displayables) to force the clickable area into what I want it to be.
The problem is : the focus masks always put themselves at the top left corner of the base image it's put on, which results in image 3. so I would like to know : how to move the displayable I use as a focus mask so it's where I want it to be ?
PS : I tried this : focus_mask Image("images/Overlay/FMs/ovl_nav_kitchen_to_evesroom_FM.png", xpos = 0, ypos = -100)
instead of this : focus_mask Image("images/Overlay/FMs/ovl_nav_kitchen_to_evesroom_FM.png", xpos = 0, ypos = 0)
In my game I created buttons to navigate from one place to an other (image1), which only appear when the mouse hovers over them (image2, see code). Problem is, the text I put in the overlay image is not always inside the area I want to be clickable, so I want to use focus masks (as displayables) to force the clickable area into what I want it to be.
The problem is : the focus masks always put themselves at the top left corner of the base image it's put on, which results in image 3. so I would like to know : how to move the displayable I use as a focus mask so it's where I want it to be ?
PS : I tried this : focus_mask Image("images/Overlay/FMs/ovl_nav_kitchen_to_evesroom_FM.png", xpos = 0, ypos = -100)
instead of this : focus_mask Image("images/Overlay/FMs/ovl_nav_kitchen_to_evesroom_FM.png", xpos = 0, ypos = 0)
- m_from_space
- Veteran
- Posts: 302
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: misplaced focus_mask
Maybe your problem is that you reposition your button image via the Image() function. But I didn't test it. Your imagebutton has some strange code in it, since renpy automatically detects images. Why use xpos = 0 and ypos = 0?
What does your focus mask image actually look like?
I assume this should work:
What does your focus mask image actually look like?
I assume this should work:
Code: Select all
imagebutton:
idle "empty"
hover "ovl_nav_kitch_to_lvroom"
focus_mask "ovl_nav_kitchen_to_evesroom_FM"
...
Re: misplaced focus_mask
If I'm honest, the whole Image("images/Overlay/FMs/ovl_nav_kitchen_to_evesroom_FM.png", xpos = 0, ypos = 0) is a copy/paste I took at the very beginning when i started using renpy, and I've been using images this way ever since. Besides, when my "idle" and "hover" are not the same size, it allows me to align them correctly. However my issue has nothing to do with the "idle" and "hover" images in this case, it has to do with the focus_mask displayable.
After trying to write my images the way you did, renpy is not able to find images.
Now to answer your question, my focus mask looks like the red shape I'm showing on image3 (which is the top one for some reason)
After trying to write my images the way you did, renpy is not able to find images.
Now to answer your question, my focus mask looks like the red shape I'm showing on image3 (which is the top one for some reason)
- PyTom
- Ren'Py Creator
- Posts: 15893
- 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: misplaced focus_mask
I haven't had a chance to test this, but right now the focus_mask isn't positioned, so it's always in the top-left of the button. If you want something that can be positioned, wrap the image inside Fixed, and n put the image inside the fixed.
For example:
The fixed will have the size of the button.
For example:
Code: Select all
focus_mask Fixed(Image("images/Overlay/FMs/ovl_nav_kitchen_to_evesroom_FM.png", yalign=1.0))
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3636
- Joined: Mon Dec 14, 2015 5:05 am
- Location: Your monitor
- Contact:
Re: misplaced focus_mask
Typically I just let the alpha determine the focus mask by adding a 99% transparent background to the image where you want to be clickable,
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Free Android GUI - Updated occasionally
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
- m_from_space
- Veteran
- Posts: 302
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: misplaced focus_mask
Uhm, shouldn't this all be way easier if you make the focus mask just the same size as the button image? As a creator I would create the button and then in the same image create a focus mask, hiding the button layer and save it as the focus mask. I don't know why people would make different sized focus masks. XD
- m_from_space
- Veteran
- Posts: 302
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
- Ocelot
- Eileen-Class Veteran
- Posts: 1882
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: misplaced focus_mask
That is exactly what expected: RenPy does not check subdirectories for images when only filename is provided.m_from_space wrote: ↑Fri Jun 10, 2022 2:48 amThat doesn't seem right tbh. You sure your filenames match the strings (don't add .png or .jpg at the end)?
< < insert Rick Cook quote here > >
- m_from_space
- Veteran
- Posts: 302
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: misplaced focus_mask
Not true Ocelot, Renpy is getting all images inside the images folder and its subdirectories. (My files are in subdirectories all the time.)Ocelot wrote: ↑Fri Jun 10, 2022 3:07 amThat is exactly what expected: RenPy does not check subdirectories for images when only filename is provided.m_from_space wrote: ↑Fri Jun 10, 2022 2:48 amThat doesn't seem right tbh. You sure your filenames match the strings (don't add .png or .jpg at the end)?
Code: Select all
The image directory is named "images", and is placed under the game directory. When a file with the .jpg or .png extension is placed underneath this directory, the extension is stripped, the rest of the filename is forced to lowercase, and the resulting filename is used as the image name if an image with that name has not been previously defined.
This process takes place in all directories underneath the image directory.
Re: misplaced focus_mask
This worked perfectly, thank you very much!PyTom wrote: ↑Thu Jun 09, 2022 4:56 pmI haven't had a chance to test this, but right now the focus_mask isn't positioned, so it's always in the top-left of the button. If you want something that can be positioned, wrap the image inside Fixed, and n put the image inside the fixed.
For example:
The fixed will have the size of the button.Code: Select all
focus_mask Fixed(Image("images/Overlay/FMs/ovl_nav_kitchen_to_evesroom_FM.png", yalign=1.0))
Re: misplaced focus_mask
Funny you should say that, I personally don't see the point of adding a focus_mask if it's exactly the size of the base image, as the default focus size is already the size of the base image. The reason I'm adding a focus mask on my navigation buttons is that I have a clickable area AND an annotation (in the same image), the annotation making the image bigger I don't want the annotation area to be clickable.m_from_space wrote: ↑Fri Jun 10, 2022 2:39 amUhm, shouldn't this all be way easier if you make the focus mask just the same size as the button image? As a creator I would create the button and then in the same image create a focus mask, hiding the button layer and save it as the focus mask. I don't know why people would make different sized focus masks. XD
Re: misplaced focus_mask
I considered doing that, but then the fully opaque text would be an area of focus too, and I don't want that. I want only the square part to be clickable.
- Ocelot
- Eileen-Class Veteran
- Posts: 1882
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: misplaced focus_mask
This relates to autodefining images, not for filename-based access. Even so, autodefined image names never contain underscore (since it is considered separator by default). For example, RenPy will define "fms ovl nav kitchen to evesroom dm" image — "fms" as image tag and the rest are attributes.m_from_space wrote: ↑Fri Jun 10, 2022 6:36 amNot true Ocelot, Renpy is getting all images inside the images folder and its subdirectories. (My files are in subdirectories all the time.)
Source: https://www.renpy.org/doc/html/displaying_images.htmlCode: Select all
The image directory is named "images", and is placed under the game directory. When a file with the .jpg or .png extension is placed underneath this directory, the extension is stripped, the rest of the filename is forced to lowercase, and the resulting filename is used as the image name if an image with that name has not been previously defined. This process takes place in all directories underneath the image directory.
< < insert Rick Cook quote here > >
- m_from_space
- Veteran
- Posts: 302
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: misplaced focus_mask
I kind of have the impression we talking about different things or you don't get the idea of focus masks or what I suggested.Misamor98 wrote: ↑Fri Jun 10, 2022 7:02 amFunny you should say that, I personally don't see the point of adding a focus_mask if it's exactly the size of the base image, as the default focus size is already the size of the base image. The reason I'm adding a focus mask on my navigation buttons is that I have a clickable area AND an annotation (in the same image), the annotation making the image bigger I don't want the annotation area to be clickable.
A focus mask is useful for example, if you have a round button and don't want the whole rectangular button image to be clickable. You create a focus mask that's round and renpy will only make the opaque parts clickable on that button image. So far so easy.
So in your case you do it like this: Create your image (including the annotation). Save the image (let's say it's 200x50px). Then create the focus mask inside the image by painting a solid structure in a new layer. Hide the button image layer and only save the focus mask layer as a .png. So both the image and the focus mask are the same dimension and you don't have to worry about placing the focus mask, since it perfectly overlaps the original image. I hope I make sense. **edit: Example attached.
Yeah I wasn't talking about using image paths inside functions, but as part of normal renpy statements. That's what I suggested to OP inside the imagebutton statement. Auto-definded images can also have underscores. Try it out!Ocelot wrote: ↑Fri Jun 10, 2022 11:05 amThis relates to autodefining images, not for filename-based access. Even so, autodefined image names never contain underscore (since it is considered separator by default). For example, RenPy will define "fms ovl nav kitchen to evesroom dm" image — "fms" as image tag and the rest are attributes.
- Attachments
-
- focus_mask.png (335 Bytes) Viewed 228 times
-
- button_image.png (3.47 KiB) Viewed 228 times
Who is online
Users browsing this forum: No registered users