piskelapp / piskel

A simple web-based tool for Spriting and Pixel art.
http://piskelapp.com
Apache License 2.0
11.06k stars 769 forks source link

Instead of duplicating frames, set delay frames on a frame #670

Open Aerotune opened 7 years ago

Aerotune commented 7 years ago

I would like to be able to simply set how many frames a single frame should be shown for. Usually I just duplicate one frame a bunch of times in piskel if I want to get the timing right for my animation or I duplicate the frames in my game engine.

It's not a must have feature but it would be a nice addition. I tried to take a look into the piskel project to see if I could code it myself but I'm not sure how to work with it yet.

https://github.com/juliandescottes/piskel/compare/master...Aerotune:master

juliandescottes commented 7 years ago

Great idea!

Your first changes are going in the right direction. The next step is to make sure that everywhere we assemble the sprite to animate it, export it (etc...) we actually take into account the delay.

For instance for the animation preview on the top right, the code to modify is at: https://github.com/juliandescottes/piskel/blob/master/src/js/controller/preview/PreviewController.js#L264-L289

In this particular example we have two spots that are impacted by this change:

The index is simply calculated based on the time so it should take the frame delays into account. We probably can't simply change the methods mentioned above to always consider the delay, as they might be used in other files to get the "actual" frame at index.

Maybe we could introduce similar methods hasRenderedFrameAt, mergeRenderedFrameAt (or parametrize the existing methods with an additional boolean).

Let's try to do that for the animated preview and then we can move on?

After that we will need to modify the GIF, PNG, ZIP... export controllers. Then we will need to modify the way we save the sprite to keep this information.

(Right now when we save, each layer only stores its name, opacity, frame count and its frames as a spritesheet png. We will need to also store the delays now, probably as a map from frameIndex -> delay . And we also need to decide if the saved spritesheet duplicates the frames that have a delay. There is an impact on piskelapp-website if we want to do that, but let's leave it for later :) )

Aerotune commented 7 years ago

Ah thanks, I'll keep looking into this! Would having checkbox option for if you want to export duplicates for gif, png, zip, ... as actual duplicate images be a viable solution?

rgriffogoes commented 7 years ago

Hey, I was looking through the issues and I think this one is a duplicate of #244