Using function to play sfx during ImageDissolve transitions?

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
sheetcakeghost
Veteran
Posts: 383
Joined: Sat Sep 19, 2009 9:19 pm
Contact:

Using function to play sfx during ImageDissolve transitions?

#1 Post by sheetcakeghost »

EDIT: Reading lower posts gets us to the idea of using functions to do this.

So I'm trying to get my teleport transitions to automatically play a sound effect when used (so that I don't have to manually play the sound effect each time I use it.) I adapted the voice beep code into this.

Code: Select all

init python:
    def telein(event, **kwargs):
        if event == "show":
            renpy.music.play("snd/vfx/teleport.mp3", channel="sfx01")
        elif event == "slow_done" or event == "end":
            renpy.music.stop(channel="sound")
But I can't really get it to work, and I don't actually know what I'm doing anyway to work out what exactly would need to be changed to make it work.

The code I'm using to make the teleport transitions is kinda old (and copy pasted from a tutorial) plus I'm not sure if I could do something similar with another sort of updated code.

Code: Select all

#Teleport In/Out
    $ slowtele = ImageDissolve("img/fx/teleportalt11.png", 5.0, 8)
    $ telein = ImageDissolve("img/fx/teleportalt11.png", 1.0, 8)
    $ teleinramp = ImageDissolve("img/fx/teleportalt11.png", 3.0, ramp=[ 16 * i for i in range(0, 15) + range(15, 0, -1) + range(0, 15) + range(15, 0, -1) + range(0, 15)  + range(15, 0, -1) + range(0, 15) ] )
    $ teleout = ImageDissolve("img/fx/teleportalt11.png", 1.0, 8, reverse=True)
Now the code works fine, I'm not complaining about it, but it being an ImageDissolve probably makes it harder, if not impossible, to attach a sound effect to it. I considered trying to use ATL, but from my research it looks like ATL doesn't like ImageDissolve all that much. I also have no clue how I would go about adapting it over to start with.
Last edited by sheetcakeghost on Sun Feb 07, 2016 12:57 pm, edited 1 time in total.

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Auto play sfx during custom transitions?

#2 Post by philat »

Eh... why not just write a function combines showing the image (renpy.show) and playing the sounds (renpy.music blah blah)?

User avatar
sheetcakeghost
Veteran
Posts: 383
Joined: Sat Sep 19, 2009 9:19 pm
Contact:

Re: Auto play sfx during custom transitions?

#3 Post by sheetcakeghost »

I have no idea how to do that, but I'll look into writing functions. Thanks!

User avatar
sheetcakeghost
Veteran
Posts: 383
Joined: Sat Sep 19, 2009 9:19 pm
Contact:

Re: Auto play sfx during custom transitions?

#4 Post by sheetcakeghost »

So I tried writing the function thing, and ended up with this.

Code: Select all

init python:
  def teleport():
      telein = ImageDissolve("img/fx/teleportalt11.png", 1.0, 8)
      teleout = ImageDissolve("img/fx/teleportalt11.png", 1.0, 8, reverse=True)
      renpy.sound.play('snd/sfx/pw-hit.mp3')
Though when I try and use it, it tells me that "telein" and "teleout" are not defined. If I define them (by unhashtagging the $ telein) it, obviously, uses that rather than the function and so doesn't play the sound effect.

Could I maybe get an example code of what this is supposed to look like, please?

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Auto play sfx during custom transitions?

#5 Post by philat »

Code: Select all

image test = "image path here"

init python:
    def teleport(image, transition):
        renpy.music.play("sound path here", channel='sound')
        renpy.show(image)
        renpy.with_statement(transition)

label start:
    $ teleport("test", telein)
    "test"

User avatar
sheetcakeghost
Veteran
Posts: 383
Joined: Sat Sep 19, 2009 9:19 pm
Contact:

Re: Auto play sfx during custom transitions?

#6 Post by sheetcakeghost »

Okay, so I really just have no idea what I'm doing here. I tried to adapt the example code to this.

Code: Select all

image teleport1 = "img/fx/teleportalt11.png"

init python:
    def portin(teleport1, ImageDissolve):
        renpy.music.play("snd/sfx/pw-hit.mp3", channel='sound')
        renpy.show(teleport1)
        renpy.with_statement(ImageDissolve, 1.0, 8)
        
init python:
    def portout(teleport1, ImageDissolve):
        renpy.music.play("snd/sfx/pw-hit.mp3", channel='sound')
        renpy.show(teleport1)
        renpy.with_statement(ImageDissolve, 1.0, 8, reverse=True)

label start:
    "let's see"
    $ teleport("test", portin)
    show pw with portin
    "test"
return
I get an error telling me teleport () takes no arguements and 2 are given. When I hashtag out the $ teleport it gives me an "old_widget" error. If I leave $ teleport and hastag out show pw I get the same teleport two arguments message.

When I make the $ teleport thing up there "$ teleport()" it plays the noise but doesn't do the transition. (Probably because, without the show it doesn't know what to load in.) If I change the show in the function to "renpy.show(pw)" where pw is the image code for the character, it again only plays the sound and doesn't do the transition.

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Using function to play sfx during ImageDissolve transiti

#7 Post by philat »

Did you read the documentation on renpy.show and renpy.with_statement? renpy.show is the equivalent of the show statement. The function is not designed to be used with the show statement. It's meant to replace it.

Just delete everything other than the transitions you have defined and the teleport function that I gave you. Call teleport with an image and transition name. (In ny example I used telein, which you defined.)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Andredron, Semrush [Bot]