使用 C++ 创建补间函数?
应该如何使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我为 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