我有触摸问题。我有一些单词sprite,我将触摸事件(下面)绑定到它们。 在我连续几次触摸其中一个并且他们想要拖动之后,首先触摸事件没有响应,但是如果我等待一秒然后我可以拖动。在LogCat我得到了这个:
12-28 17:23:58.979:V / AndEngine(23295):org.andengine.util.adt.pool.PoolUpdateHandler $ 1已用尽,1件物品尚未回收。分配了1个。
如何解决此问题?
以下是触摸事件代码:
public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY)
{
switch(pSceneTouchEvent.getAction()) {
case TouchEvent.ACTION_DOWN:
this.mGrabbed = true;
break;
case TouchEvent.ACTION_MOVE:
if(this.mGrabbed)
this.setPosition(pSceneTouchEvent.getX() - 18, pSceneTouchEvent.getY() - 15);
break;
case TouchEvent.ACTION_UP:
if(this.mGrabbed)
{
this.mGrabbed = false;
boolean found = false;
float x1,x2,y1,y2;
if(this.getY() < 350)
{
for(int i = 0; i < positions_list.size(); i++)
{
if((word_object_list.get(a).getName().equals(positions_list.get(i).getName())) && positions_list.get(i).isFree())
{
x1 = word_object_list.get(a).getSprite().getX();
y1 = word_object_list.get(a).getSprite().getY();
x2 = positions_list.get(i).getxPosition();
y2 = positions_list.get(i).getyPosition();
x1 = Math.abs(x2-x1);
y1 = Math.abs(y2-y1);
x1 = (float) Math.pow(x1,2);
y1 = (float) Math.pow(y1, 2);
x1 = x1+y1;
x1 = (float) Math.sqrt(x1);
if(x1 < 20)
{
// Set hint's visibility false
if(i == 0 && sprite_word_hint_1 != null)
sprite_word_hint_1.setVisible(false);
if(i == random_hint_position && sprite_word_hint_2 != null)
sprite_word_hint_2.setVisible(false);
word_object_list.get(a).getSprite().setVisible(false);
sprite_word_true_list.get(i).setVisible(true);
sprite_candy_list.get(finish_state).setVisible(true);
finish_state ++;
if(finish_state == question.getWord().length())
{
// Create new scene
Game_Screen.this.getEngine().registerUpdateHandler(new TimerHandler(6.5f, new ITimerCallback() {
public void onTimePassed(TimerHandler pTimerHandler) {
// TODO Auto-generated method stub
Game_Screen.this.getEngine().setScene(load_new_scene());
remove_textures();
}
}));
// Increase point
Game_Screen.this.getEngine().registerUpdateHandler(new TimerHandler(4.3f, new ITimerCallback() {
public void onTimePassed(TimerHandler pTimerHandler) {
// TODO Auto-generated method stub
int point = variables.getDatabase().get_point(variables.getCategory_level())+question.getWord().length();
elapsedText.setText(""+point);
variables.getDatabase().set_answered(question);
variables.getDatabase().update_user(question, question.getWord().length(), hint_used);
}
}));
// Cover animation
sprite_cover.setRotationCenter(sprite_cover.getRotationCenterX()+20, sprite_cover.getRotationCenterY());
sprite_cover.registerEntityModifier(new SequenceEntityModifier(
new DelayModifier(1),
new RotationModifier(1.5f, 0, 90),
new DelayModifier(1.7f),
new RotationModifier(1, 90, -0)
)
);
// Candy animation
for(int j = 0; j < sprite_candy_list.size(); j++)
{
sprite_candy_list.get(j).registerEntityModifier(new SequenceEntityModifier(
new DelayModifier(2.7f),
new CubicBezierCurveMoveModifier( 1.5f, sprite_candy_list.get(j).getX(), sprite_candy_list.get(j).getY(), 165, 240, 166, 241, 275, 400, EaseQuadIn.getInstance()),
new DelayModifier(0.2f),
new AlphaModifier(1, 1, 0)
)
);
}
}
positions_list.get(i).setFree(false);
found = true;
break;
}
}
}
}
if(!found)
{
word_object_list.get(a).getSprite().registerEntityModifier(new MoveModifier(1, word_object_list.get(a).getSprite().getX(), word_object_list.get(a).getPositionX(), word_object_list.get(a).getSprite().getY(), word_object_list.get(a).getPositionY(),EaseQuadIn.getInstance()));
}
}
break;
}
return true;
}
答案 0 :(得分:0)
我找到了答案。当我多次触摸sprite时,每次它注册一个实体修饰符并且堆栈正在增长时,我应该等到它为空。然后我添加了
this.clearEntityModifiers();
函数调用触摸事件的开头,它工作正常。