Problem with cache and sound
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.
Problem with cache and sound
I have this line:
m "My name is John" #here starts to play the sound of the below Shake function.
m "Whats up"
m "Hi guy"
m "Stop" with Shake((0.5, 1.0, 0.5, 1.0), 1.0, dist=5)
That Shake function is in the official documentation. Simply I've add a sound to this function to play a sound meanwhile the shaking effect.
The problem is in the previous dialogue when the sound is also played. I think this issue is related to cache. How can I avoid it?
Thanks.
m "My name is John" #here starts to play the sound of the below Shake function.
m "Whats up"
m "Hi guy"
m "Stop" with Shake((0.5, 1.0, 0.5, 1.0), 1.0, dist=5)
That Shake function is in the official documentation. Simply I've add a sound to this function to play a sound meanwhile the shaking effect.
The problem is in the previous dialogue when the sound is also played. I think this issue is related to cache. How can I avoid it?
Thanks.
- theCodeCat
- Regular
- Posts: 62
- Joined: Sun Sep 06, 2015 8:40 pm
- Projects: Lucid9, Mystic Destinies: Serendipity of Aeons
- Skype: theCodeCat
- Contact:
Re: Problem with cache and sound
Can you show the code for how you added the sound effect to 'Shake'?
You might have added it in such a way that the sound is triggered when the object is created, and not necessarily when the visual effect is executed.
You might have added it in such a way that the sound is triggered when the object is created, and not necessarily when the visual effect is executed.
Re: Problem with cache and sound
Code: Select all
#Shake effect
init:
python:
import math
class Shaker(object):
anchors = {
'top' : 0.0,
'center' : 0.5,
'bottom' : 1.0,
'left' : 0.0,
'right' : 1.0,
}
def __init__(self, start, child, dist):
if start is None:
start = child.get_placement()
#
self.start = [ self.anchors.get(i, i) for i in start ] # central position
self.dist = dist # maximum distance, in pixels, from the starting point
self.child = child
def __call__(self, t, sizes):
# Float to integer... turns floating point numbers to
# integers.
def fti(x, r):
if x is None:
x = 0
if isinstance(x, float):
return int(x * r)
else:
return x
xpos, ypos, xanchor, yanchor = [ fti(a, b) for a, b in zip(self.start, sizes) ]
xpos = xpos - xanchor
ypos = ypos - yanchor
nx = xpos + (1.0-t) * self.dist * (renpy.random.random()*2-1)
ny = ypos + (1.0-t) * self.dist * (renpy.random.random()*2-1)
return (int(nx), int(ny), 0, 0)
def _Shake(start, time, child=None, dist=100.0, **properties):
renpy.sound.play("sound/effects/shock2.ogg")
move = Shaker(start, child, dist=dist)
return renpy.display.layout.Motion(move,
time,
child,
add_sizes=True,
**properties)
Shake= renpy.curry(_Shake)
Last edited by runs on Mon Jul 11, 2016 5:47 pm, edited 2 times in total.
- theCodeCat
- Regular
- Posts: 62
- Joined: Sun Sep 06, 2015 8:40 pm
- Projects: Lucid9, Mystic Destinies: Serendipity of Aeons
- Skype: theCodeCat
- Contact:
Re: Problem with cache and sound
I think it might work if you move the "renpy.sound.play("sound/effects/shock2.ogg")" line into the __init__ function of the 'Shaker' class.
So something like:
So something like:
Code: Select all
def __init__(self, start, child, dist):
renpy.sound.play("sound/effects/shock2.ogg")
<rest of code>
Re: Problem with cache and sound
Thankx, theCodeCat, but that does not solve the problem.
I've finally done the trick making a function called from the Shake function:
I've finally done the trick making a function called from the Shake function:
Code: Select all
#Shake effect
init:
python:
import math
class Shaker(object):
anchors = {
'top' : 0.0,
'center' : 0.5,
'bottom' : 1.0,
'left' : 0.0,
'right' : 1.0,
}
def __init__(self, start, child, dist):
if start is None:
start = child.get_placement()
#
self.start = [ self.anchors.get(i, i) for i in start ] # central position
self.dist = dist # maximum distance, in pixels, from the starting point
self.child = child
def __call__(self, t, sizes):
# Float to integer... turns floating point numbers to
# integers.
def fti(x, r):
if x is None:
x = 0
if isinstance(x, float):
return int(x * r)
else:
return x
xpos, ypos, xanchor, yanchor = [ fti(a, b) for a, b in zip(self.start, sizes) ]
xpos = xpos - xanchor
ypos = ypos - yanchor
nx = xpos + (1.0-t) * self.dist * (renpy.random.random()*2-1)
ny = ypos + (1.0-t) * self.dist * (renpy.random.random()*2-1)
return (int(nx), int(ny), 0, 0)
def _Shake(start, time, child=None, dist=100.0, **properties):
SoundShock
move = Shaker(start, child, dist=dist)
return renpy.display.layout.Motion(move,
time,
child,
add_sizes=True,
**properties)
def SoundShock(self):
renpy.sound.play("sound/effects/shock2.ogg")
Shake= renpy.curry(_Shake)Who is online
Users browsing this forum: Bing [Bot], enaielei