Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Vlad

I have a situation where I'd benefit from AnimationSheet object where I don't have to specify frame size in pixels but instead frame count per image. In particular, trying to deliver a game to multiple platforms in native resolution (say, web, iPhone, iPhone 4, iPad, ...) and at 1:1 scale, I need to change the code for each.

I propose the AnimationSheetFrames object which extends AnimationSheet and takes instead of width and height in pixels, width and height in frames. To get to pixels the class would simply divide image width and height with this numbers respectively.

I intend to write such an object but I guess I'd have to hook it into Image object's loading flow and specify AnimationSheet dims once the image size is known. I also suppose that common usage of Animation is through init() meaning AnimationSheets (if, again commonly instantiated as class properties) would be defined, images loaded (and dims known) before the Animation objects are spawned.

1 decade ago by MikeL

That's interesting Vlad. At some point I would like to do something similar. Have you looked into using the inject function? I used it in a fairly trivial way here. I am also using it more extensively to modify the Animation class to do some specific type of drawing.

That could be a way to go and maybe prevent having to directly modify the core impact classes.

1 decade ago by Vlad

Thanks for the suggestion, I didn't pay much attention to the inject() method. With this I add addAnimFrames() method to the ig.Entity which is exact copy of addAnim() method except it recalculates animation sheet size in px from its width and height given as frame count. This is a quick and dirty way to get what I want, otherwise I'd have to modify both the ig.Image and ig.AnimationSheet.

ig.Entity .addAnimFrames() works perfectly but it is fragile:

1.) If ig.Entity.addAnim() is changed by a future update, this might break.
2.) AnimationSheet is used in an undocumented way (width and height given are not px but frame count)


If only ig.Image had optional onload callback given through its init() which it passes directly to its load() this would be trivial to implement by extending AnimationSheet with an init that does the same but supplies a callback which recalculates px size.

Of course the only reason I suggest AnimationSheetFrames is for backward compatibility. That, or introduce one more parameter, a flag which states whether the dims given are px or frames. That way same class name can do both and retain backwards compatibility.
Page 1 of 1
« first « previous next › last »