Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
simpleaudio replaced kivy audio loader (audio loader was bugged for me)
Browse files Browse the repository at this point in the history
  • Loading branch information
salt-die committed Jan 24, 2020
1 parent 4bbd99b commit 4c1977e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions circumstantial-companions/stone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from kivy.clock import Clock
from kivy.uix.widget import Widget
from kivy.graphics import Color, Rectangle
from kivy.core.audio import SoundLoader
from PIL import Image
import numpy as np
import simpleaudio as sa


GRAVITY = .02
Expand Down Expand Up @@ -127,7 +127,10 @@ class Chisel(Widget):
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.sound = SoundLoader.load(SOUND)
self.sound = sa.WaveObject.from_wave_file(SOUND)
self.looped_sound = Clock.schedule_interval(self.play_sound, 1)
self.looped_sound.cancel()
self.play = None

self.set_radius(DEFAULT_CHISEL_RADIUS)
self.set_power(DEFAULT_CHISEL_POWER)
Expand Down Expand Up @@ -199,15 +202,23 @@ def poke(self, touch):
i, z, velocity = info.values()
self.pebbles[i] = Pebble(i, self, x, y, z, velocity)

def play_sound(self, dt=0):
if self.play is None or not self.play.is_playing():
self.play = self.sound.play()

def on_touch_down(self, touch):
self.poke(touch)
self.sound.play()
self.play_sound()
return True

def on_touch_move(self, touch):
self.poke(touch)
self.looped_sound()
return True

def on_touch_up(self, touch):
self.looped_sound.cancel()

def reset(self):
self.canvas.clear()
self.setup_canvas()
Expand Down

0 comments on commit 4c1977e

Please sign in to comment.