How can I execute a series of actions on a single touch? For example, if I have this example from the Pythonista documentation but I want to shoot say 3 lasers, one right after the other or with a slight pause between. I tried adding the three lines defining the laser, it’s action, and it’s sound in a loop, but instead of firing the lasers in succession it fired all three at once.
Second question, is there a “do while touch” method that would repeatedly fire lasers while the touch is held?
EDIT:
Updated script to include Action.sequence. I get an error that the action sequence does not include any actions.
from scene import *
import sound
import random
import math
class MyScene (Scene):
def setup(self):
self.background_color = 'midnightblue'
self.ship = SpriteNode('spc:PlayerShip1Orange')
self.ship.position = self.size / 2
self.add_child(self.ship)
def update(self):
x, y, z = gravity()
pos = self.ship.position
pos += (x * 15, y * 15)
# Don't allow the ship to move beyond the screen bounds:
pos.x = max(0, min(self.size.w, pos.x))
pos.y = max(0, min(self.size.h, pos.y))
self.ship.position = pos
def touch_began(self, touch):
self.run_action(Action.sequence(self.fire_laser(),self.fire_laser(),self.fire_laser()))
def fire_laser(self):
a=random.random()*500-250
laser = SpriteNode('spc:LaserBlue9', position=self.ship.position, z_position=-1, parent=self)
laser.run_action(Action.sequence(Action.move_by(a, 1000), Action.remove()))
sound.play_effect('arcade:Laser_1')