Example #1
0
class AnimationExamples(Scene):
    def __init__(self):
        Scene.__init__(self, SIZE)
        bg = spyral.Image(size=SIZE)
        bg.fill(BG_COLOR)
        self.background = bg
        
        font = spyral.Font(None, FONT_SIZE, FG_COLOR)
        
        self.title = TextSprite(self, font)
        self.title.anchor = 'center'
        self.title.pos = (SIZE[0] / 2, 30)
        self.title.render("N")
        
        self.block = Sprite(self)
        self.block.image = spyral.Image(size=(40,40))
        self.block.image.fill(FG_COLOR)
        self.block.y = 300
        
        self.index = 0
        
        self.set_animation()
        
        instructions = TextSprite(self, font)
        instructions.anchor = 'midbottom'
        instructions.x = 320
        instructions.y = 470
        instructions.render("n: next example  p: previous example  q: quit")
        
        # Register all event handlers
        self.register('system.quit', sys.exit)
        self.register('input.keyboard.down.p', self.previous)
        self.register('input.keyboard.down.n', self.next)
        self.register('input.keyboard.down.q', sys.exit)
        self.register('input.keyboard.down.escape', sys.exit)

                                
    def set_animation(self):
        self.title.render(ANIMATIONS[self.index][0])
        self.block.stop_all_animations()
        self.block.y = 300 # Reset the y-coordinate.
        a = ANIMATIONS[self.index][1] + DELAY
        a.loop = True
        self.block.animate(a)
        
    def next(self):
        self.index += 1
        self.index %= len(ANIMATIONS)
        self.set_animation()
        
    def previous(self):
        self.index -= 1
        self.index %= len(ANIMATIONS)
        self.set_animation()
Example #2
0
class AnimationExamples(Scene):
    def __init__(self):
        Scene.__init__(self, SIZE)
        bg = spyral.Image(size=SIZE)
        bg.fill(BG_COLOR)
        self.background = bg

        font = spyral.Font(None, FONT_SIZE, FG_COLOR)

        self.title = TextSprite(self, font)
        self.title.anchor = 'center'
        self.title.pos = (SIZE[0] / 2, 30)
        self.title.render("N")

        self.block = Sprite(self)
        self.block.image = spyral.Image(size=(40, 40))
        self.block.image.fill(FG_COLOR)
        self.block.y = 300

        self.index = 0

        self.set_animation()

        instructions = TextSprite(self, font)
        instructions.anchor = 'midbottom'
        instructions.x = 320
        instructions.y = 470
        instructions.render("n: next example  p: previous example  q: quit")

        # Register all event handlers
        spyral.event.register('system.quit', spyral.director.quit)
        spyral.event.register('input.keyboard.down.p', self.previous)
        spyral.event.register('input.keyboard.down.n', self.next)
        spyral.event.register('input.keyboard.down.q', spyral.director.quit)
        spyral.event.register('input.keyboard.down.escape',
                              spyral.director.quit)

    def set_animation(self):
        self.title.render(ANIMATIONS[self.index][0])
        self.block.stop_all_animations()
        self.block.y = 300  # Reset the y-coordinate.
        a = ANIMATIONS[self.index][1] + DELAY
        a.loop = True
        self.block.animate(a)

    def next(self):
        self.index += 1
        self.index %= len(ANIMATIONS)
        self.set_animation()

    def previous(self):
        self.index -= 1
        self.index %= len(ANIMATIONS)
        self.set_animation()
Example #3
0
class AnimationExamples(Scene):
    def __init__(self):
        Scene.__init__(self)
        self.camera = self.parent_camera.make_child(SIZE)
        self.group = Group(self.camera)

        font = spyral.Font(None, FONT_SIZE, FG_COLOR)

        self.title = TextSprite(self.group, font)
        self.title.anchor = 'center'
        self.title.pos = (SIZE[0] / 2, 30)
        self.title.render("N")

        self.block = Sprite(self.group)
        self.block.image = spyral.Image(size=(40, 40))
        self.block.image.fill(FG_COLOR)
        self.block.y = 300

        self.index = 0

        self.set_animation()

        instructions = TextSprite(self.group, font)
        instructions.anchor = 'midbottom'
        instructions.x = 320
        instructions.y = 470
        instructions.render("n: next example  p: previous example  q: quit")

    def on_enter(self):
        bg = spyral.Image(size=SIZE)
        bg.fill(BG_COLOR)
        self.camera.set_background(bg)

    def render(self):
        self.group.draw()

    def set_animation(self):
        self.title.render(ANIMATIONS[self.index][0])
        self.block.stop_all_animations()
        self.block.y = 300  # Reset the y-coordinate.
        a = ANIMATIONS[self.index][1] + DELAY
        a.loop = True
        self.block.animate(a)

    def next(self):
        self.index += 1
        self.index %= len(ANIMATIONS)
        self.set_animation()

    def previous(self):
        self.index -= 1
        self.index %= len(ANIMATIONS)
        self.set_animation()

    def update(self, dt):
        for event in self.event_handler.get():
            if event['type'] == 'QUIT':
                spyral.quit()
                sys.exit()
            if event['type'] == 'KEYDOWN':
                if event['ascii'] == 'p':
                    self.previous()
                elif event['ascii'] == 'n':
                    self.next()
                elif event['ascii'] == 'q':
                    spyral.quit()
                    sys.exit()

        self.group.update(dt)
Example #4
0
class AnimationExamples(Scene):
    def __init__(self):
        Scene.__init__(self)
        self.camera = self.parent_camera.make_child(SIZE)
        self.group = Group(self.camera)
        
        font = spyral.Font(None, FONT_SIZE, FG_COLOR)
        
        self.title = TextSprite(self.group, font)
        self.title.anchor = 'center'
        self.title.pos = (SIZE[0] / 2, 30)
        self.title.render("N")
        
        self.block = Sprite(self.group)
        self.block.image = spyral.Image(size=(40,40))
        self.block.image.fill(FG_COLOR)
        self.block.y = 300
        
        self.index = 0
        
        self.set_animation()
        
        instructions = TextSprite(self.group, font)
        instructions.anchor = 'midbottom'
        instructions.x = 320
        instructions.y = 470
        instructions.render("n: next example  p: previous example  q: quit")
                
    def on_enter(self):
        bg = spyral.Image(size=SIZE)
        bg.fill(BG_COLOR)
        self.camera.set_background(bg)
                
    def render(self):
        self.group.draw()
        
    def set_animation(self):
        self.title.render(ANIMATIONS[self.index][0])
        self.block.stop_all_animations()
        self.block.y = 300 # Reset the y-coordinate.
        a = ANIMATIONS[self.index][1] + DELAY
        a.loop = True
        self.block.animate(a)
        
    def next(self):
        self.index += 1
        self.index %= len(ANIMATIONS)
        self.set_animation()
        
    def previous(self):
        self.index -= 1
        self.index %= len(ANIMATIONS)
        self.set_animation()
        
    def update(self, dt):
        for event in self.event_handler.get():
            if event['type'] == 'QUIT':
                spyral.quit()
                sys.exit()
            if event['type'] == 'KEYDOWN':
                if event['ascii'] == 'p':
                    self.previous()
                elif event['ascii'] == 'n':
                    self.next()
                elif event['ascii'] == 'q':
                    spyral.quit()
                    sys.exit()
                    
        self.group.update(dt)