Example #1
0
 def create_animation_by_grids_inverse(self, image_name, duration, rotation,
                                       rows, columns):
     effect_seq = pyglet.image.ImageGrid(self.image(image_name, rotation),
                                         rows, columns)
     effect_frames = []
     for row in range(rows, 0, -1):
         end = row * columns
         start = end - (columns - 1) - 1
         for effect_frame in effect_seq[start:end:1]:
             effect_frames.append(AnimationFrame(effect_frame, duration))
     effect_frames[(rows * columns) - 1].duration = None
     return Animation(effect_frames)
Example #2
0
    def __init__(self):
        self.prefix = 'beerthrow'
        numFrames = 3

        imgs, flipImgs = self.loadImgsAndFlipImgs(False, numFrames,
                                                  self.prefix)

        duration = 0.1
        frames = [AnimationFrame(x, duration) for x in imgs]
        self.animation = Animation(frames)
        pyglet.sprite.Sprite.__init__(self, self.animation)
        self.done = False
Example #3
0
    def create_animation_by_rows(self, image_name, duration, rotation, brow,
                                 rows, column, columns):
        effect_seq = pyglet.image.ImageGrid(self.image(image_name, rotation),
                                            rows, columns)
        effect_frames = []
        end = brow * columns
        start = end - (columns - 1)
        for effect_frame in effect_seq[start:end:1]:
            effect_frames.append(AnimationFrame(effect_frame, duration))

        effect_frames[((rows - brow) * (columns - column)) - 1].duration = None
        return Animation(effect_frames)
Example #4
0
def create_effect_animation(self, image_name, columns, rows):
    effect_seq = pyglet.image.ImageGrid(pyglet.image.load(image_name), rows,
                                        columns)
    effect_frames = []
    for row in range(rows, 0, -1):
        end = row * columns
        start = end - (columns - 1) - 1
        for effect_frame in effect_seq[start:end:1]:
            effect_frames.append(AnimationFrame(effect_frame, 0.1))

    effect_frames[(rows * columns) - 1].duration = None
    return Animation(effect_frames)
Example #5
0
def createAnimation(image=None, columns=0, rows=0, anchor_x=0, anchor_y=0):
    #effect_seq = pyglet.image.ImageGrid(pyglet.image.load(image_name), rows, columns)
    effect_seq = pyglet.image.ImageGrid(image, rows, columns)
    effect_frames = []
    for row in range(rows, 0, -1):
        end = row * columns
        start = end - (columns - 1) - 1
        for effect_frame in effect_seq[start:end:1]:
            effect_frame.anchor_x = anchor_x
            effect_frame.anchor_y = anchor_y
            effect_frames.append(AnimationFrame(effect_frame, 0.3))

    #effect_frames[(rows * columns) -1].duration = None
    return Animation(effect_frames)
 def __init__(self, pos):
     from pyglet.image import Animation, AnimationFrame
     im1 = pyglet.resource.image('wheels.png')
     im2 = pyglet.resource.image('wheels2.png')
     im3 = pyglet.resource.image('wheels3.png')
     t = 0.05
     anim = Animation([
         AnimationFrame(im1, t),
         AnimationFrame(im2, t),
         AnimationFrame(im3, t),
     ])
     self.sprite1 = pyglet.sprite.Sprite(anim)
     self.sprite2 = pyglet.sprite.Sprite(anim)
     self.sprite2.color = (64, 64, 64)
     self.pos = pos
Example #7
0
def animationByList(image=None, aniList=[]):

    effect_frames=[]

    tmpImageY = image.height
    print(tmpImageY)

    for f in aniList:

        tmpFrame = image.get_region(f["x"], f["y"], f["w"], f["h"])
        tmpFrame.anchor_x = f["anchor_x"]
        tmpFrame.anchor_y = f["anchor_y"]
        effect_frames.append(AnimationFrame(tmpFrame, f["duration"]))

    return Animation(effect_frames)
Example #8
0
    def create_animation_by_frames(self,
                                   image_frames,
                                   duration=1.0,
                                   rotation=0,
                                   looped=False,
                                   anchor_x=0,
                                   anchor_y=0):
        frames = []
        for img in image_frames:
            image = self.image(img, rotation)
            self._anchor_image(image, anchor_x, anchor_y)
            # self._center_image(image)
            frames.append(AnimationFrame(image, duration))

        if looped is False:
            frames[len(image_frames) - 1].duration = None
        return Animation(frames=frames)
Example #9
0
def setup_animations(actor, sprites):
    animations = []

    for i in sprites:
        sprites.fill_rgba(i)
        reverse(i)

    for animation in actor.animations:
        image_frames = []
        speed = 0.5 * animation.speed / len(animation.frames)
        for subframes in animation.frames:
            for frame in subframes:
                if frame.direction != 0:
                    continue
                frame = apply_actor(sprites, frame)
                animation_frame = (AnimationFrame(frame, speed))
                image_frames.append(animation_frame)
        if len(image_frames):
            animations.append(Animation(image_frames))
    return animations
Example #10
0
def load_animation(slp_file,
                   frame_ids,
                   duration=0.1,
                   mirrored=False,
                   player=1):
    """
        Load some frames from the slp fil into an `pyglet.image.Animation` instance.
        *frame_ids* is a tuple ``(first frame, last frame)`` (inclusive).
        *duration* is the number of seconds to display the frame.
        If the frames should be mirrored horizontally, pass True for *mirrored*.
        You can also pass a player number as *player*.

        Return a `pyglet.image.Animation` instance.
    """
    adapter = MirroredPygletAdapter if mirrored else PygletAdapter
    anim_frames = []
    for frame_id in xrange(frame_ids[0], frame_ids[1] + 1):
        frame = slp_file.frames[frame_id]
        img = frame.parse_stream(image_adapter_cls=adapter, player=player)
        anim_frames.append(AnimationFrame(img, duration))
    return Animation(anim_frames)
Example #11
0
    def decode_animation(self, filename, file):
        if not file:
            file = open(filename, 'rb')
        # If file is not an animated GIF, it will be loaded as a single-frame animation.
        file_bytes = file.read()
        data = c_void_p(cf.CFDataCreate(None, file_bytes, len(file_bytes)))
        sourceRef = c_void_p(quartz.CGImageSourceCreateWithData(data, None))

        # Get number of frames in the animation.
        count = quartz.CGImageSourceGetCount(sourceRef)

        frames = []

        for index in range(count):
            # Try to determine frame duration from GIF properties dictionary.
            duration = 0.1  # default duration if none found
            props = c_void_p(
                quartz.CGImageSourceCopyPropertiesAtIndex(
                    sourceRef, index, None))
            if cf.CFDictionaryContainsKey(props,
                                          kCGImagePropertyGIFDictionary):
                gif_props = c_void_p(
                    cf.CFDictionaryGetValue(props,
                                            kCGImagePropertyGIFDictionary))
                if cf.CFDictionaryContainsKey(gif_props,
                                              kCGImagePropertyGIFDelayTime):
                    duration = cfnumber_to_number(
                        c_void_p(
                            cf.CFDictionaryGetValue(
                                gif_props, kCGImagePropertyGIFDelayTime)))

            cf.CFRelease(props)
            image = self._get_pyglet_ImageData_from_source_at_index(
                sourceRef, index)
            frames.append(AnimationFrame(image, duration))

        cf.CFRelease(data)
        cf.CFRelease(sourceRef)

        return Animation(frames)