删除动画 [英] Deleting Animations

查看:67
本文介绍了删除动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作游戏。我需要在这个

案例动画(爆炸和东西)中维护一堆对象。我决定使用STL

向量。根据我的理解,我需要将其声明为

vector< Animation *以便我可以插入新的动画与

,如myAnimations.push_back(新动画(... ));所以这一切都很好

和花花公子,但我不能决定如何删除这个动画

玩完之后(爆炸应该被删除并从矢量中移除

,当它完成循环所有它的帧时。我已经告诉他们这是一个坏主意,让一个对象删除自己,因为

然后调用者不知道它是否仍然存在存在,并且它只是一个糟糕的设计决定。那么,最好在我的动画对象中使用某种类型的

布尔值来表示类似

" animationComplete",当设置为true时,迭代器将会

删除它?如果是这样,我的迭代器会是什么样子?


for(vector< Animation *> :: iterator current = myAnimations.begin();

current != myAnimations.end();当前++)

{

(*当前) - > step(); //告诉动画更改帧

并做任何需要做的事

if((* current) - > animationComplete)

{

current = projectile.erase(当前);

delete(* current); //< - 是吗?

继续;

}

(*当前) - > draw(); //画它

}


代码看起来有点难看......这真的是最好的方法吗?

解决方案

4月27日,05:53,Mark< mnbaya ... @ gmail.comwrote:


我正在制作游戏。我需要在这个

案例动画(爆炸和东西)中维护一堆对象。我决定使用STL

向量。根据我的理解,我需要将其声明为

vector< Animation *以便我可以插入新的动画与

,如myAnimations.push_back(新动画(... ));所以这一切都很好

和花花公子,但我不能决定如何删除这个动画

玩完之后(爆炸应该被删除并从矢量中移除

,当它完成循环所有它的帧时。我已经告诉他们这是一个坏主意,让一个对象删除自己,因为

然后调用者不知道它是否仍然存在存在,并且它只是一个糟糕的设计决定。那么,最好在我的动画对象中使用某种类型的

布尔值来表示类似

" animationComplete",当设置为true时,迭代器将会

删除它?如果是这样,我的迭代器会是什么样子?


for(vector< Animation *> :: iterator current = myAnimations.begin();

current != myAnimations.end();当前++)

{

(*当前) - > step(); //告诉动画更改帧

并做任何需要做的事

if((* current) - > animationComplete)

{

current = projectile.erase(当前);

delete(* current); //< - 是吗?

继续;

}

(*当前) - > draw(); //画它

}


代码看起来有点难看......这真的是最好的方法吗?



是否有任何特殊原因你不能将其声明为

vector< Animation并添加如下新元素:

''myAnimations.push_back(动画(...))'',注意缺少新的?


然后你所要做的就是用擦除()要删除的向量

它们,我认为可以添加一个谓词来擦除它以便它只删除那些dynamicComplete为真的那些。


-

Erik Wikstr?m




标记 < mn ******* @ gmail.com>

??????:11 ******************* ***@r3g2000prh.googleg roups.com ...


我正在制作游戏。我需要在这个

案例动画(爆炸和东西)中维护一堆对象。我决定使用STL

向量。根据我的理解,我需要将其声明为

vector< Animation *以便我可以插入新的动画与

,如myAnimations.push_back(新动画(... ));所以这一切都很好

和花花公子,但我不能决定如何删除这个动画

玩完之后(爆炸应该被删除并从矢量中移除

,当它完成循环所有它的帧时。我已经告诉他们这是一个坏主意,让一个对象删除自己,因为

然后调用者不知道它是否仍然存在存在,并且它只是一个糟糕的设计决定。那么,最好在我的动画对象中使用某种类型的

布尔值来表示类似

" animationComplete",当设置为true时,迭代器将会

删除它?如果是这样,我的迭代器会是什么样子?


for(vector< Animation *> :: iterator current = myAnimations.begin();

current != myAnimations.end();当前++)

{

(*当前) - > step(); //告诉动画更改帧

并做任何需要做的事

if((* current) - > animationComplete)

{

current = projectile.erase(当前);

delete(* current); //< - 是吗?

继续;

}

(*当前) - > draw(); //画它

}


代码看起来有点难看......这真的是最好的方法吗?


我想它应该是:


delete(* current); //首先

current = projectile.erase(当前); //第二个


我几乎使用list作为

for(it = list.begin(); it!= list.end();)

{

if((* it).die())

{

delete * it;

it = list.erase(it)

}

else

++ it;

}




抱歉发布未完成的邮件。

我的意思是你最好选择清单比矢量更好。


mos。


I''m making a game. I need to maintain a bunch of objects, in this
case animations (explosions and stuff). I''ve decided to use an STL
vector. From my understanding, I need to declare it as
vector<Animation*so that I can insert new animations with something
like myAnimations.push_back(new Animation(...)); So that''s all fine
and dandy, but what I can''t decide on is how to delete this animation
after it''s done playing (the explosion should be deleted and removed
from the vector when it''s done cycling through all it''s frames). I''ve
been told it''s a bad idea to get an object to delete itself, because
then the caller won''t know whether or not it still exists, and it''s
just a bad design decision. So, would it be best to have some sort of
boolean in my animation object that says something like
"animationComplete", and when set to true the iterator would then
remove it? If so, what would my iterator look like?

for( vector<Animation*>::iterator current = myAnimations.begin();
current != myAnimations.end(); current++ )
{
(*current)->step(); // tells the animation to change frames
and do whatever it needs to do
if( (*current)->animationComplete )
{
current = projectile.erase(current);
delete (*current); // <-- is this right?
continue;
}
(*current)->draw(); // draw it
}

Code looks kind of ugly... is that really the best way of doing it?

解决方案

On 27 Apr, 05:53, Mark <mnbaya...@gmail.comwrote:

I''m making a game. I need to maintain a bunch of objects, in this
case animations (explosions and stuff). I''ve decided to use an STL
vector. From my understanding, I need to declare it as
vector<Animation*so that I can insert new animations with something
like myAnimations.push_back(new Animation(...)); So that''s all fine
and dandy, but what I can''t decide on is how to delete this animation
after it''s done playing (the explosion should be deleted and removed
from the vector when it''s done cycling through all it''s frames). I''ve
been told it''s a bad idea to get an object to delete itself, because
then the caller won''t know whether or not it still exists, and it''s
just a bad design decision. So, would it be best to have some sort of
boolean in my animation object that says something like
"animationComplete", and when set to true the iterator would then
remove it? If so, what would my iterator look like?

for( vector<Animation*>::iterator current = myAnimations.begin();
current != myAnimations.end(); current++ )
{
(*current)->step(); // tells the animation to change frames
and do whatever it needs to do
if( (*current)->animationComplete )
{
current = projectile.erase(current);
delete (*current); // <-- is this right?
continue;
}
(*current)->draw(); // draw it
}

Code looks kind of ugly... is that really the best way of doing it?

Is there any special reason why you don''t just declare it as
vector<Animationand add new elements like this:
''myAnimations.push_back(Animation(...))'', notice the lack of new?

Then all you have to do is to use erase() on the vector to delete
them, I think it''s possible to add a predicate to erase so that it
only erases those where animationComplete is true.

--
Erik Wikstr?m



"Mark" <mn*******@gmail.com>
??????:11**********************@r3g2000prh.googleg roups.com...

I''m making a game. I need to maintain a bunch of objects, in this
case animations (explosions and stuff). I''ve decided to use an STL
vector. From my understanding, I need to declare it as
vector<Animation*so that I can insert new animations with something
like myAnimations.push_back(new Animation(...)); So that''s all fine
and dandy, but what I can''t decide on is how to delete this animation
after it''s done playing (the explosion should be deleted and removed
from the vector when it''s done cycling through all it''s frames). I''ve
been told it''s a bad idea to get an object to delete itself, because
then the caller won''t know whether or not it still exists, and it''s
just a bad design decision. So, would it be best to have some sort of
boolean in my animation object that says something like
"animationComplete", and when set to true the iterator would then
remove it? If so, what would my iterator look like?

for( vector<Animation*>::iterator current = myAnimations.begin();
current != myAnimations.end(); current++ )
{
(*current)->step(); // tells the animation to change frames
and do whatever it needs to do
if( (*current)->animationComplete )
{
current = projectile.erase(current);
delete (*current); // <-- is this right?
continue;
}
(*current)->draw(); // draw it
}

Code looks kind of ugly... is that really the best way of doing it?

I suppose it should be :

delete (*current); // first
current = projectile.erase(current); // second

and I almost use list as
for (it = list.begin(); it != list.end(); )
{
if ((*it).die())
{
delete *it;
it = list.erase(it)
}
else
++it;
}


Hi
sorry for posting unfinished mail.
I mean you''d better choose list to do it than vector.

mos.


这篇关于删除动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆