[SOLVED] restart_interaction() refreshes music

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
Shlizer
Newbie
Posts: 7
Joined: Fri Sep 03, 2021 12:47 am
Github: https://github.com/Shlizer
Contact:

[SOLVED] restart_interaction() refreshes music

#1 Post 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:

Code: Select all

    $ ui.add(mousePosition)
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?
Last edited by Shlizer on Mon Jan 17, 2022 4:58 pm, edited 1 time in total.

User avatar
emz911
Regular
Posts: 103
Joined: Fri Jun 23, 2017 2:23 pm
Contact:

Re: restart_interaction() refreshes music

#2 Post 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

Shlizer
Newbie
Posts: 7
Joined: Fri Sep 03, 2021 12:47 am
Github: https://github.com/Shlizer
Contact:

Re: restart_interaction() refreshes music

#3 Post 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.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: restart_interaction() refreshes music

#4 Post 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.
< < insert Rick Cook quote here > >

Shlizer
Newbie
Posts: 7
Joined: Fri Sep 03, 2021 12:47 am
Github: https://github.com/Shlizer
Contact:

Re: restart_interaction() refreshes music

#5 Post 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.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: restart_interaction() refreshes music

#6 Post 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.
< < insert Rick Cook quote here > >

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: restart_interaction() refreshes music

#7 Post 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

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: restart_interaction() refreshes music

#8 Post by Ocelot »

Alex wrote: Mon Jan 17, 2022 12:35 pm renpy.music.play has 'if_changed" property - try to set it to True.
https://www.renpy.org/doc/html/audio.ht ... music.play
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.
< < insert Rick Cook quote here > >

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: restart_interaction() refreshes music

#9 Post by Alex »

Ocelot wrote: Mon Jan 17, 2022 12:45 pm
Alex wrote: Mon Jan 17, 2022 12:35 pm renpy.music.play has 'if_changed" property - try to set it to True.
https://www.renpy.org/doc/html/audio.ht ... music.play
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

Shlizer
Newbie
Posts: 7
Joined: Fri Sep 03, 2021 12:47 am
Github: https://github.com/Shlizer
Contact:

Re: restart_interaction() refreshes music

#10 Post by Shlizer »

Ocelot wrote: Mon Jan 17, 2022 11:10 amYou 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).
Alex wrote: Mon Jan 17, 2022 4:50 pm

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
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 =/

Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Majestic-12 [Bot]