Haxe:无帧关键帧动画

发布于 2024-07-11 07:03:42 字数 896 浏览 5 评论 0原文

我想在 Haxe (flash9) 中做简单的(循环)动画(移动、改变 alpha 等)。 我的库中没有任何类似于框架的东西,只有单帧资源。

由于我是初学者。 我不一定要寻找一个复杂的框架。 我会很高兴能快速完成一些事情。 肮脏的。 也许if检查frame(类变量)并线性插值值。

class MyClass extends Sprite {
    static var frame:Int = 0;
    static inline var framerate:Int = 25;

    static function main() {
        var app:MyClass = new MyClass();
        flash.Lib.current.addChild(app);
    }

    private function new() {
        super();

        // init assets here

        var myTimer:Timer = new Timer(1000/framerate);
        myTimer.addEventListener(TimerEvent.TIMER, animate);
        myTimer.start();
    }

    function animateForeground(event:TimerEvent) {
        frame = (frame + 1) % 1000;

        // set new values depending on frame
    }

}

我知道关键帧动画的基本思想。 我正在寻找更多关于如何构建程序的这一部分

您能给我一些关于我应该如何进行的指示吗?

I would like to do simple (looping) animation (moving, changing alpha etc) in Haxe (flash9). I don't have anything that resembles frames in my library, just single frame assets.

Since I am a beginner. I am not necessarily looking for a sophisticated framework. I would be happy with something quick & dirty. Maybe ifs checking the frame (class variable) and linearly interpolating the values.

class MyClass extends Sprite {
    static var frame:Int = 0;
    static inline var framerate:Int = 25;

    static function main() {
        var app:MyClass = new MyClass();
        flash.Lib.current.addChild(app);
    }

    private function new() {
        super();

        // init assets here

        var myTimer:Timer = new Timer(1000/framerate);
        myTimer.addEventListener(TimerEvent.TIMER, animate);
        myTimer.start();
    }

    function animateForeground(event:TimerEvent) {
        frame = (frame + 1) % 1000;

        // set new values depending on frame
    }

}

I know the basic idea of keyframe animation. What I am looking for is more about how to structure this part of the program.

Can you please give me some pointers on how should I proceed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

┈┾☆殇 2024-07-18 07:03:42

如果你想做动画,我强烈建议使用补间库,尽管我理解在“作弊”之前你可能想先学习基础知识。

我建议将动画连接到 ENTER_FRAME 事件,而不是以与帧速率相同的速度运行的计时器。 实际上没有必要将这两者解耦,因为计时器并不比 ENTER_FRAME 事件更可靠,并且如果无论如何都看不到它,则无需移动内容。

另外,我认为您不应该过多关注“关键帧”动画。 当您拥有关键帧时,这是一个有用的概念,如果没有关键帧,那么采用感觉上最好的实现方式会更实用。

我会在这里放置一些代码,但是我很难想出任何代码,因为我不太确定您想在这里实现什么目标。

If you want to do animations I would very much recommend using a tweening library, although I understand that you might want to learn the basics before "cheating" past them.

I would recommend hooking up your animations to the ENTER_FRAME event instead of a timer running at the same speed as your framerate. There's really no need to decouple these two, since the timer isn't any more reliable than the ENTER_FRAME event, and there's no need in moving stuff around if it can't be seen anyway.

Also, I don't think you should focus that much on "keyframe" animation. That is a useful concept when you have keyframes, if you don't it's way more practical just to do what feels like the best way to implement this.

I would put some code in here, but I'm having a little bit of a hard time coming up with any since I'm not really sure what you're trying to achieve here.

汹涌人海 2024-07-18 07:03:42

罗伯特·彭纳的书中的 chapter7_tweening.pdf 可能值得一读,尽管现在已经过时了就代码而言,它涵盖了补间的概念。

但也许不值得重新发明轮子...

Feffect 是一个很好的跨平台补间引擎, Actuate 使用起来更简单、速度更快。 使用宏进行补间可能是最好的方法,但开始可能有点复杂( 小叮当)。

It is probably worth reading chapter7_tweening.pdf from Robert Penner's book, although now very out of date in terms of the code, it covers the concept of tweening.

But maybe not worth reinventing the wheel...

Feffect's is a good cross platform tweening engine, Actuate is simpler to use and fast. Using macros for tweening is maybe the best approach but maybe it is a bit complex to start ( tinkerbell ).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文