使用 C++ 创建补间函数?

发布于 2024-10-04 11:27:07 字数 1160 浏览 4 评论 0原文

应该如何使用 C++ 创建一个用于补间某些内容的接口?例如,我想使用静态函数调用在五秒内淡入图片,例如:

Graphics::FadeSurface( Surface mySurface, int FrameHeight, int NumOfFrames,
   int FadeDirection, double Duration )

我有一个硬编码设置,可以为每个需要执行的补间操作创建一个对象。我一直在使用 DeltaTime 变量来跟踪自程序启动以来已经过去了多少时间来控制逻辑等。我提供了一个示例(不太精致)来向您展示我正在尝试做的事情:

示例逻辑循环:


gameLoop( double DeltaTime ){

    // ...
    // logic
    // ...

    bool isItDone = otherClass.HaveFiveSecondsElapsed( double DeltaTime );

    if( isItDone == true )
        exit(1);

    // ...
    // logic
    // ... 

}

示例补间类:


other_Class::other_Class(){

    InitialTime = 0;
    InitialTime_isSet = false;

}

bool other_class::HaveFiveSecondsElapsed( double DeltaTime ){

    // Setting InitialTime if it hasn't already been set
    if( otherClass.InitialTime_isSet == false ){

        otherClass.InitialTime = DeltaTime;
        otherClass.InitialTime_isSet = true;

    }

    bool toReturn = false;

    if( DeltaTime - InitialTime > 5 )
        toReturn = true;

    return toReturn;

}

任何帮助都非常重要赞赏。谢谢!

How should one create an interface for tweening something using C++? For instance, I want to fade a picture in over a duration of five seconds using a static function call like:

Graphics::FadeSurface( Surface mySurface, int FrameHeight, int NumOfFrames,
   int FadeDirection, double Duration )

I have a hard-coded setup that creates an object for each tween action that needs to be performed. I have been using a DeltaTime variable that keeps track of how much time has passed since the program has launched to control logic and such. I've included an example (much less refined) to show you kind of what I'm trying to do:

Example Logic Loop:


gameLoop( double DeltaTime ){

    // ...
    // logic
    // ...

    bool isItDone = otherClass.HaveFiveSecondsElapsed( double DeltaTime );

    if( isItDone == true )
        exit(1);

    // ...
    // logic
    // ... 

}

Example Tweening Class:


other_Class::other_Class(){

    InitialTime = 0;
    InitialTime_isSet = false;

}

bool other_class::HaveFiveSecondsElapsed( double DeltaTime ){

    // Setting InitialTime if it hasn't already been set
    if( otherClass.InitialTime_isSet == false ){

        otherClass.InitialTime = DeltaTime;
        otherClass.InitialTime_isSet = true;

    }

    bool toReturn = false;

    if( DeltaTime - InitialTime > 5 )
        toReturn = true;

    return toReturn;

}

Any help is greatly appreciated. Thanks!

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

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

发布评论

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

评论(1

眼中杀气 2024-10-11 11:27:07

我为 java 构建了一个 Tween 引擎,它足够通用,可以用于补间任何对象的任何属性。通用部分是通过定义“Tweenable”接口来完成的,用户需要实现该接口来补间其对象。

我强烈鼓励您使用它作为构建引擎的灵感,或者直接移植它。我还可以计划一个自制的 C++ 移植,但是要使其与当前的 java 版本(增长非常快)保持同步需要做大量工作。

http://code.google.com/p/java-universal-tween -engine/

注意:我在这个问题中对这个引擎做了更详细的回答:
Android:位图的补间动画

I built a Tween engine for java that is generic enough to be used to tween any attribute of any object. The generic part is done through the definition of a "Tweenable" interface that users need to implement to tween their objects.

I greatly encourage you to use it as inspiration to build your engine, or directly port it. I can also plan a home-made port to C++, but it would be quite a lot of work to maintain it up-to-date with the current java version (which grows very fast).

http://code.google.com/p/java-universal-tween-engine/

NB: I made a more elaborated answer about this engine in this question:
Android: tween animation of a bitmap

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