I did some reading up on Aseprite. It's a nice program, and I think it 
might be nice to make a loader for the binary .aseprite/.ase format at some 
point as well. It's binary, but well defined and looks easy to parse.

In your case, it might be simplest to just subclass the Sprite module, and 
override the *_animate* method. Here is the original method:
    def _animate(self, dt):
        self._frame_index += 1
        if self._frame_index >= len(self._animation.frames):
            self._frame_index = 0
            self.dispatch_event('on_animation_end')
            if self._vertex_list is None:
                return  # Deleted in event handler.

        frame = self._animation.frames[self._frame_index]
        self._set_texture(frame.image.get_texture())

        if frame.duration is not None:
            duration = frame.duration - (self._next_dt - dt)
            duration = min(max(0, duration), frame.duration)
            clock.schedule_once(self._animate, duration)
            self._next_dt = duration
        else:
            self.dispatch_event('on_animation_end')

As you can see, it uses the duration attribute of the frames themselves to 
advance. I would suggest that you add a *Sprite.animation_speed* property 
to your subclass of the *Sprite *class, and then modify the 
*Sprite._animate* method to use that value instead. This would be simple to 
change the speed.   If you go this route, you could also easily update any 
frame index properties as well from within the _animate method. 


On Friday, January 6, 2017 at 2:13:02 AM UTC+9, Solar Lune wrote:
>
> Aseprite allows you to export a standard sprite sheet, and export timing 
> information and tags to a JSON file. I'm loading that file in to create the 
> animations and tags from - the data class is currently a container that 
> holds the loaded set of animations, tags, and a reference to the pyglet 
> Sprite itself. 
>
> In another engine, I also created functions that you could use to tell 
> when you hit specific tags (for example, a "spawn" tag in a shooting 
> animation) - that's what I'd like to add here, too, for simplicity and 
> ease-of-use.
>
> I'll see about exposing this frame index to the data class I have so that 
> the user can tell what frame the animation's on - perhaps also a function 
> that gives a percentage completed.
>
> Being able to tweak the animation speed of a "currently running" animation 
> is also important, so that's what I was looking into. Seems like it might 
> be good to add a multiplication value to Animations so that it's easier to 
> tweak speed, rather than having to loop through each frame and alter its 
> duration (since that takes processor speed to do).
>
> Thanks for the information!
>
> On Thu, Jan 5, 2017 at 5:54 AM, Benjamin Moran <benmo...@gmail.com 
> <javascript:>> wrote:
>
>> That sounds like an interesting project. What kind of format will your 
>> data be in?
>>
>> The Sprite class does not currently have any public attributes that show 
>> the animation details, but it *is* possible to access this information. 
>> If you create a Sprite with an animation, it will have a private attribute 
>> with the current frame (this attribute will not exist if the sprite uses a 
>> static image):
>> >>> sprite = pyglet.sprite.Sprite(img=some_animation)
>> >>> sprite._frame_index
>> 0
>>
>> As for animation speed:
>> If you're creating an animation from a sequence of images, or a sprite 
>> sheet (ImageGrid), you can specify the animation speed on creation. 
>> There is not currently a standard way of controlling animation speed 
>> after creation, but there are some ways you could to it. The trick is that 
>> each frame in an animation has it's own duration attribute. The Sprite 
>> class simply plays these frames in order. One way to do it would be to 
>> simple re-create the animation and update the sprites *image* attribue with 
>> the new animation. Another way would be to iterate through the animations 
>> frames, and modify their duration attribute. If you post a little more 
>> about what you're trying to accomplish, it would be easier to recommend 
>> something. 
>>
>> -Ben
>>
>>
>>
>> On Thursday, January 5, 2017 at 7:15:37 PM UTC+9, Solar Lune wrote:
>>>
>>> Hey, there. So, I'm doing work on creating a quick little Python module 
>>> to auto-load tags and animations in from Aseprite into pyglet, but before I 
>>> go further, I wanted to confirm: Is there no way to control how quickly a 
>>> sprite is playing, or know where in the animation a sprite is (apart from 
>>> when it hits the end of the animation)?
>>>
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "pyglet-users" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/pyglet-users/3Pp3VHtoAto/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> pyglet-users...@googlegroups.com <javascript:>.
>> To post to this group, send email to pyglet...@googlegroups.com 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/pyglet-users.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pyglet-users+unsubscr...@googlegroups.com.
To post to this group, send email to pyglet-users@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to