Page 1 of 1
How to deal with slow imagebutton hover feedback
Posted: Sun Jan 02, 2022 10:18 pm
by searchwindows
Code: Select all
#lotion
imagebutton auto "images/homeinteractive/bathroom/lotion_%s.png":
focus_mask "images/homeinteractive/bathroom/lotion_focus.png"
action Jump("lotion")
So for example moving the mouse cursor over an imagebutton(lotion_%s.png) makes my lotion_hover.png show.
But moving the cursor very fast back and forth over the imagebutton
doesn't make lotion_hover.png show.
So, fast moving cursors cause the imagebuttons to not respond, and it feels sluggish and laggy.
Is there a fix to this problem?
Re: How to deal with slow imagebutton hover feedback
Posted: Mon Jan 03, 2022 6:59 am
by strayerror
The short answer is: no.
The longer answer is that it's a performance issue that comes with using focus_mask with an image. Each time the cursor moves Ren'Py has to look up the corresponding pixel in the mask, check if it's transparent, and then either abort or execute the normal focus behaviour. Work has been done to improve that performance in one of the more recent versions (roughly sometime in the last six months), but there's still going to be a noticeable performance impact when using the feature.
The extreme answer is that focus_mask will accept a Python callable that takes the arguments x, y and will focus if that callable returns True, so in the unlikely case that your lotion_focus mask is easily defined in a Python function (or you wish to fall off the deep end and try your hand at determining the mask status with custom code), then that could be an option, but as it looks like this would be just one of many imagebuttons in your scenario, I doubt this approach would be scalable.
Sorry to be the bearer of bad news :( ... but hope it helps. :)
Re: How to deal with slow imagebutton hover feedback
Posted: Mon Jan 03, 2022 11:45 am
by plastiekk
Hello,
I'm not sure if it's the "imagebutton auto" function, but I don't have any noticeable speed loss when I define the images first using "image my_idle_button: ... , image my_hover_button: ...".
My script currently displays 7 imagebuttons at the same time (and I'm sure there will be more), all of which can be hovered without any really noticeable delays. (My test laptop is a good 5 years old. I5+geeforce 710m GPU).
An image button itself looks like this:
Code: Select all
imagebutton at from_gina_left: # just a movein_left transition
focus_mask True # <- True aswell
idle "play_gina" # here we show the images defined in "images.rpy"
hover "play_gina_hover" # or whereever you defined them
hovered Show("tooltip_gina") # a tooltip
unhovered Hide("tooltip_gina")
action Play("sound","/a_chord1.wav"), Hide("tooltip_gina"), [SetVariable('game_player', ('gina')), Return('start_game')]
The image definitions take some effort, but it might be worth a try. (But maybe I'm completely barking up the wrong tree

)
Re: How to deal with slow imagebutton hover feedback
Posted: Mon Jan 03, 2022 4:52 pm
by searchwindows
plastiekk wrote: ↑Mon Jan 03, 2022 11:45 am
Hello,
I'm not sure if it's the "imagebutton auto" function, but I don't have any noticeable speed loss when I define the images first using "image my_idle_button: ... , image my_hover_button: ...".
My script currently displays 7 imagebuttons at the same time (and I'm sure there will be more), all of which can be hovered without any really noticeable delays. (My test laptop is a good 5 years old. I5+geeforce 710m GPU).
An image button itself looks like this:
Code: Select all
imagebutton at from_gina_left: # just a movein_left transition
focus_mask True # <- True aswell
idle "play_gina" # here we show the images defined in "images.rpy"
hover "play_gina_hover" # or whereever you defined them
hovered Show("tooltip_gina") # a tooltip
unhovered Hide("tooltip_gina")
action Play("sound","/a_chord1.wav"), Hide("tooltip_gina"), [SetVariable('game_player', ('gina')), Return('start_game')]
The image definitions take some effort, but it might be worth a try. (But maybe I'm completely barking up the wrong tree

)
I tried your method by getting rid of auto but the delay was still there :<
Re: How to deal with slow imagebutton hover feedback
Posted: Mon Jan 03, 2022 4:55 pm
by searchwindows
strayerror wrote: ↑Mon Jan 03, 2022 6:59 am
The short answer is: no.
The longer answer is that it's a performance issue that comes with using
focus_mask with an image. Each time the cursor moves Ren'Py has to look up the corresponding pixel in the mask, check if it's transparent, and then either abort or execute the normal focus behaviour. Work has been done to improve that performance in one of the more recent versions (roughly sometime in the last six months), but there's still going to be a noticeable performance impact when using the feature.
The
extreme answer is that
focus_mask will accept a Python callable that takes the arguments
x, y and will focus if that callable returns
True, so in the unlikely case that your
lotion_focus mask is easily defined in a Python function (or you wish to fall off the deep end and try your hand at determining the mask status with custom code), then that could be an option, but as it looks like this would be just one of many imagebuttons in your scenario, I doubt this approach would be scalable.
Sorry to be the bearer of bad news

... but hope it helps.
My current lotion idle.png and hover.png has a resolution set at 1920x1080 instead of setting it the size of the lotion. So that I can skip the process of positioning the imagebutton. Would setting a smaller resolution for clickables enhance the speed at all?
Re: How to deal with slow imagebutton hover feedback
Posted: Tue Jan 04, 2022 3:27 am
by strayerror
By default Ren'Py does some clever stuff when loading textures such that it automatically determines the bounding box of non-transparent pixels to avoid loading lots of null space into video memory, that may make checks outside that area less costly, but that's speculation on my part.
That the area of each image button is effectively full screen probably means that at a minimum the mask check is run for every button each time the mouse is moved, even if that check ends up potentially being cheap due to the texture magic previously mentioned, but I don't know if that would be enough to provide the speed up you're looking for. The issue noticeably impacts even relatively small buttons, especially on older hardware, but that might still yield significant improvement to you even though not eradicated completely.
tl;dr: Unfortunately your best bet is probably to pick one of your busier screens (i.e. with more buttons), and test the theory. At best you'll see an improvement, with less lag but perhaps still some, and at worst it'll behave pretty much the same because Ren'Py was effectively already doing the optimisation for you. :(
Re: How to deal with slow imagebutton hover feedback
Posted: Tue Jan 04, 2022 3:55 am
by searchwindows
strayerror wrote: ↑Tue Jan 04, 2022 3:27 am
By default Ren'Py does some clever stuff when loading textures such that it automatically determines the bounding box of non-transparent pixels to avoid loading lots of null space into video memory, that
may make checks outside that area less costly, but that's speculation on my part.
That the area of each image button is effectively full screen probably means that at a minimum the mask check is run for every button each time the mouse is moved, even if that check ends up potentially being cheap due to the texture magic previously mentioned, but I don't know if that would be enough to provide the speed up you're looking for. The issue noticeably impacts even relatively small buttons, especially on older hardware, but that might still yield significant improvement to you even though not eradicated completely.
tl;dr: Unfortunately your best bet is probably to pick one of your busier screens (i.e. with more buttons), and test the theory. At best you'll see an improvement, with less lag but perhaps still some, and at worst it'll behave pretty much the same because Ren'Py was effectively already doing the optimisation for you.
Thank you. I tried reducing about two or three imagebuttons from 1920x1080 to around 300~x 400~. But it seems to have made zero difference on reaction time. I guess I'll either have to just deal with it or find a custom code that could speed it up like you've said above, although I don't how I'd even start with it haha!
Re: How to deal with slow imagebutton hover feedback
Posted: Tue Jan 04, 2022 12:10 pm
by zmook
If you really *need* quicker reaction times because it's a mini game or something, you could try to see if it's faster to recode things as a single imagemap with hotspots.
Re: How to deal with slow imagebutton hover feedback
Posted: Wed Jan 05, 2022 3:05 am
by searchwindows
zmook wrote: ↑Tue Jan 04, 2022 12:10 pm
If you really *need* quicker reaction times because it's a mini game or something, you could try to see if it's faster to recode things as a single imagemap with hotspots.
Will single imagemap with hotpots allow multiple transparent/alpha channel areas? So like multiple png images to use as the "focus_mask" images. I've never used imagemaps before, since I've always been reading "imagemaps are old and imagebuttons are the future" and whatnot..