I'm making a sound pitch study app.
To repeat the program I used 'while and break' statement at first, but it didn't work in the 'scene'.
So I'm trying to use 'Action.repeat()' to repeat program. It works very fine.
And now I want to stop (cancel) the repeat and go back to 'setup(self)' or 'new_play(self)' screen when I touch 'stop_icon' SpriteNode automatically in the middle of the repeat program (when I don't want to repeat them10times (in my program below)).
Please help me achieve it.
from scene import *
import sound
from random import randint
#A = Action
class MyScene (Scene):
def setup(self):
self.background_color='#0000ff'
ground=Node(parent=self)
icons=['iob:ios7_play_32','iob:ios7_pause_32']
self.start_icon=SpriteNode(icons[0],position=(self.size.w/2,150))
self.start_icon.size*=3
self.stop_icon=SpriteNode(icons[1],position=(self.size.w/2,150))
self.stop_icon.size*=3
self.pmi=self.start_icon
self.add_child(self.pmi)
self.play_mode=False
def did_change_size(self):
pass
def sound_list(self):
num=randint(0,12)
sl=['piano:C4','piano:C#4','piano:D4','piano:D#4','piano:E4','piano:F4','piano:F#4','piano:G4','piano:G#4','piano:A4,'piano:A#4','piano:B4','piano:C5']
self.player=sound.Player(sl[num])
self.player.play()
def new_play(self):
self.pmi.remove_from_parent()
self.pmi=self.start_icon
self.add_child(self.pmi)
self.play_mode=False
def update(self): # I don't want to use this update() function.
pass
def touch_began(self, touch):
if self.play_mode==False:
if touch.location in self.pmi.frame:
self.pmi.remove_from_parent()
self.pmi=self.stop_icon
self.add_child(self.pmi)
self.play_mode=True
sq_1=Action.sequence(Action.call(self.sound_list),Action.wait(2.0)) # And more actions continue actually.
rp_num=10 # I want to stop Action.repeat(sounds) when I touch 'stop_icon', when I don't want to repeat 10times in this case.
rp=Action.repeat(sq_1,rp_num)
sq_2=Action.sequence(rp,Action.call(self.new_play))
self.run_action(sq_2)
elif self.play_mode==True: # I want to stop Action.repeat(sounds) when I touch 'stop_icon'(self.pmi), when I don't want to repeat 10times in this case.
if touch.location in self.pmi.frame:
self.pmi.remove_from_parent()
self.pmi=self.start_icon
self.add_child(self.pmi)
self.play_mode=False
def touch_moved(self, touch):
pass
def touch_ended(self, touch):
pass
if __name__ == '__main__':
run(MyScene(), show_fps=False)