• jellybeard

    Thanks for the replies.

    I tried a sequence (see updated example above) but it looks as if calling a method (fire_laser) doesn’t count as an action as I get an error. The ship still fires three at once.

    I tried your example too and that’s close to what I am after! The lasers stop mid flight on touch end.

    posted in Pythonista read more
  • jellybeard

    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?

    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
        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):
        def fire_laser(self):
            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()))

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!