Original Post
I have an idea for a Tween class that looks great on paper, but I am running into trouble trying to implement it. I want to be able to create Tween objects that take in a variable, and adjust it in different ways across a given time span. I then want to be able to have objects instantiate Tweens which will run automated. Essentially I want to be able to:
[source cpp]
// give object a Tween* vector
vector tweenVec;
// somewhere within the Object's code
// to tween position from its current (1, 1) to (100, 100) over 1000ms
Tween* tempTween = new Tween( &m_position.X, 100, 1000 )
tweenVec.add( tempTween );
tempTween = new Tween( &m_position.Y, 100, 1000 )
tweenVec.add( tempTween );
// then in the Object's update code:
if ( !tweenVec.empty() )
{
for each tween t
t->update( currentTime )
if t->isFinished
// delete the object and remove the pointer from the vector
}
[/source]
I thought, through my limited understanding of friends, that if I specified the Tween class as a friend in the Object's declaration code that it could access protected members. I tried making a Tween a friend, but then it wanted me to also make Object a template, which is understandable but very undesirable.
How would someone go about implementing this so object could have a vector of Tween pointers that have access to its protected data? Would knowing which data types it will work on be helpful? As in, explicitly making it friends with Tween, Tween etc? Also, will all of this be undone when I make derived Tweens with specific agorithms?
[source cpp]
// give object a Tween* vector
vector
// somewhere within the Object's code
// to tween position from its current (1, 1) to (100, 100) over 1000ms
Tween
tweenVec.add( tempTween );
tempTween = new Tween
tweenVec.add( tempTween );
// then in the Object's update code:
if ( !tweenVec.empty() )
{
for each tween t
t->update( currentTime )
if t->isFinished
// delete the object and remove the pointer from the vector
}
[/source]
I thought, through my limited understanding of friends, that if I specified the Tween class as a friend in the Object's declaration code that it could access protected members. I tried making a Tween
How would someone go about implementing this so object could have a vector of Tween pointers that have access to its protected data? Would knowing which data types it will work on be helpful? As in, explicitly making it friends with Tween