Page 1 of 1
[SOLVED] restart_interaction() refreshes music
Posted: Sun Jan 16, 2022 11:23 pm
by Shlizer
Hey,
I'm trying to do few things on screen that will depend on mouse position (eg. set position of elements or show text with cursor position).. I've got many different approaches, but currently I'm using one with adding mouse position checker as displayable on screen:
Code: Select all
class getMousePosition(renpy.Displayable):
x = 0
y = 0
def __init__(self):
renpy.Displayable.__init__(self)
def event(self, ev, x, y, st):
import pygame
if ev.type == pygame.MOUSEMOTION: # Updates the position of the mouse every time the player moves it
print self.x
self.x = x
self.y = y
renpy.restart_interaction()
def render(self, width, height, st, at):
return renpy.Render(1, 1)
mousePosition = getMousePosition()
and in screen I need it:
unfortunatelly that screen is also playing music:
Code: Select all
$ renpy.music.play("xxx.mp3", channel="music", loop=True, fadeout=2.0, fadein=4.0, relative_volume=0.4)
sadly, every time when mouse position is checked and rendered my music is being refreshed (that makes sense, since I'm using `restart_interaction()` to refresh whole screen), but I've got no idea how to prevent it =/
Has anyone idea how to actually make it work or maybe different approach will make it happen?
Re: restart_interaction() refreshes music
Posted: Mon Jan 17, 2022 2:03 am
by emz911
Why not play the music before you show the screen? For example in a label before the call screen part, Or anything that separates the music from the screen should work
Re: restart_interaction() refreshes music
Posted: Mon Jan 17, 2022 9:49 am
by Shlizer
nice idea.. I've tried to use that hint and it looks like I'm a step closer.
the problem is that I'm using it on `main_menu` screen, so after adding it in eg. `splashscreen` works really well, but if I'll try to start a game and go back to main menu it's not playing anything.
Re: restart_interaction() refreshes music
Posted: Mon Jan 17, 2022 10:14 am
by Ocelot
1) Try to use before_main_menu label. It is explicitely exist to set up things before showing main menu
2) Use main_menu label instead of main menu screen.
3) Add a renpy.music.get_playing check, and don't play music if it is already playing.
4) Do not restart interaction. Create a transform which will listen for mouse events and redraws its child accordingly.
Re: restart_interaction() refreshes music
Posted: Mon Jan 17, 2022 10:58 am
by Shlizer
Never heard of `before_main_menu`, but it works nicely..
Can you elaborate on that listening to mouse events on transform? I can't use renpy blocks in trasform I believe.
Re: restart_interaction() refreshes music
Posted: Mon Jan 17, 2022 11:10 am
by Ocelot
Shlizer wrote: ↑Mon Jan 17, 2022 10:58 am
Never heard of `before_main_menu`, but it works nicely..
Can you elaborate on that listening to mouse events on transform? I can't use renpy blocks in trasform I believe.
You can create a CDD, as you did before, but instead of just storing data, it manipulates its child based on that data. I mean, what the documentation on CDD shows you:
https://www.renpy.org/dev-doc/html/cdd.html
In your case, instead of manipilating opacity, you can manipulate position.
Re: restart_interaction() refreshes music
Posted: Mon Jan 17, 2022 12:35 pm
by Alex
Shlizer wrote: ↑Sun Jan 16, 2022 11:23 pm
...
renpy.music.play has 'if_changed" property - try to set it to True.
https://www.renpy.org/doc/html/audio.ht ... music.play
Re: restart_interaction() refreshes music
Posted: Mon Jan 17, 2022 12:45 pm
by Ocelot
I was going to add this as another potential solution, but
This will always queue up an additional loop of the music bother me. OP has screen redrawn on every mouse movement, and I am afraid of music queue filling and causing a slowdown.
Re: restart_interaction() refreshes music
Posted: Mon Jan 17, 2022 4:50 pm
by Alex
Ocelot wrote: ↑Mon Jan 17, 2022 12:45 pm
I was going to add this as another potential solution, but
This will always queue up an additional loop of the music bother me. OP has screen redrawn on every mouse movement, and I am afraid of music queue filling and causing a slowdown.
Shlizer wrote: ↑Sun Jan 16, 2022 11:23 pm
...unfortunatelly that screen is also playing music:
Code: Select all
$ renpy.music.play("xxx.mp3", channel="music", loop=True, fadeout=2.0, fadein=4.0, relative_volume=0.4)
...
Mmm, then OP could try to play music on main menu screen 'show'. like
Code: Select all
screen main_menu():
on 'show' action Play("xxx.mp3")
# or action Fuction(renpy.music.play, "xxx.mp3", channel="music", loop=True, fadeout=2.0, fadein=4.0, relative_volume=0.4, if_changed=True)
https://www.renpy.org/doc/html/screens.html#on
Re: restart_interaction() refreshes music
Posted: Mon Jan 17, 2022 4:58 pm
by Shlizer
Ocelot wrote: ↑Mon Jan 17, 2022 11:10 am
You can create a CDD, as you did before, but instead of just storing data, it manipulates its child based on that data. I mean, what the documentation on CDD shows you:
https://www.renpy.org/dev-doc/html/cdd.html
That's the first approach I did and I've got a problem with navigation - each time any button got focus on hover, my classes went to default mode, but after your suggestion I wrote it from a scratch and I don't have trat problem now. At least it works as I tried to do from beggining, thanks!
And about music - AFAIK it turns off after I change label (like for eg. start a game) and while in menu for quite some time it loops and I didn't saw much of a performance issue (but I got quite powerful PC, so tmr I'll test it on VM to check that).
BTW. I know it's not related to topic, but I saw that conditionally showing screens ignores those transitions:
Code: Select all
init python:
def printShow():
print "show"
def printHide():
print "hide"
screen main_menu():
on "show" action Function(printShow) # will fire
on "hide" action Function(printHide) # will fire
use some_screen
if important_value == True:
use conditional_sceen
screen some_screen():
on "show" action Function(printShow) # will fire
on "hide" action Function(printHide) # will fire
screen conditional_sceen():
on "show" action Function(printShow) # won't fire (even if it's content is visible)
on "hide" action Function(printHide) # won't fire
It's so counter-intuitive =/