[英]AndEngine GLES2 - How to use the Entity on which IUpdateHandler is called?
I am very new to AndEngine. 我是AndEngine的新手。 I found that I can use an Entity on which I applied MoveModifier or for some other Modifiers it may also work.
我发现我可以使用我应用MoveModifier的实体,或者对于其他一些Modifier,它也可以使用。 For example:
例如:
MoveModifier mm = new MoveModifier(1.0f,startx, starty, endx, endy) {
@Override
protected void onModifierStarted(IEntity pItem) {
//do somthing with pItem
}
@Override
protected void onModifierFinished(IEntity pItem) {
//do somthing with pItem
}
};
But I can't do the same thing with IUpdateHandler when I apply it on an Entity (Sprite). 但是当我在实体(Sprite)上应用IUpdateHandler时,我无法做同样的事情。 So, is there any way so that I can use the Entity (Sprite) from inside the Handler call?
那么,有什么方法可以让我在Handler调用中使用Entity(Sprite)吗?
Edit: 编辑:
What I actually want is something like this: 我真正想要的是这样的:
IUpdateHandler mm = new IUpdateHandler() {
@Override
protected void onModifierStarted(IEntity pItem) {
//do somthing with pItem
}
@Override
protected void onModifierFinished(IEntity pItem) {
//do somthing with pItem
}
};
But this doesn't work. 但这不起作用。 Any other way or is there a way to pass anything as the IUpdateHandler parameter?
任何其他方式或有没有办法传递任何作为IUpdateHandler参数?
add to your modifier 添加到修改器
@Override
protected void onManagedUpdate(float pSecondsElapsed, IEntity pItem) {
//add your actions
super.onManagedUpdate(pSecondsElapsed, pItem);
}
Actually it is not possible in case of IUpdateHandler to have the entity locally like the MoveModifier. 实际上,在IUpdateHandler的情况下,不可能像MoveModifier一样在本地拥有实体。 So I had to declare the Entity globally and then use it inside the IUpdateHandler.
所以我必须全局声明实体,然后在IUpdateHandler中使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.