1

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!

recursive404
  • 13
  • 1
  • 4

1 Answers1

1

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

Community
  • 1
  • 1
Aurelien Ribon
  • 7,548
  • 3
  • 43
  • 54
  • This is exactly what I was looking to do - thanks a ton for this. The funny thing is I currently have that C++ project on old and am working on an Android game using LibGDX, so this will suit my needs perfectly :] – recursive404 Apr 14 '11 at 13:35
  • Nice to see this is helpful :) Don't hesitate to talk about your project on the libgdx forums, it has a wonderful community. Once I'll have a dedicated website for the Tween Engine with tutorials, showcase and tools, I'll port it to C++ (first) and then .NET, in order for it to be totally universal. – Aurelien Ribon Apr 14 '11 at 14:00