2012-06-27 34 views
1

我想使用更新处理程序来增加精灵的比例。但是,它不允许调用场景动作提升事件,所以精灵的大小继续增加。如何在动作结束时让更新处理程序中断?这是我有:当动作启动时(AndEngine),我如何获取场景更新处理程序?

的更新处理:

scene.registerUpdateHandler(new IUpdateHandler() { 

     @Override 
     public void reset() {   
     } 

     @Override 
     public void onUpdate(float pSecondsElapsed) { 
      if(fillerNum>-1){ 
       if(filler[fillerNum].active){ 

        mPhysicsWorld.unregisterPhysicsConnector(mPhysicsWorld.getPhysicsConnectorManager().findPhysicsConnectorByShape(filler[fillerNum].sprite)); 
        mPhysicsWorld.destroyBody(filler[fillerNum].body); 

        filler[fillerNum].sprite.setScale(filler[fillerNum].scale+=pSecondsElapsed*3); 

        filler[fillerNum].body = PhysicsFactory.createCircleBody(mPhysicsWorld, filler[fillerNum].sprite, BodyType.DynamicBody, FIXTURE_DEF); 
        mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(filler[fillerNum].sprite, filler[fillerNum].body, true, true)); 
       } 
      }    
     } 
    }); 

场面触摸事件:

@Override 
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) { 
    if(this.mPhysicsWorld != null) { 
      if(pSceneTouchEvent.isActionDown()) { 
       createFiller(pSceneTouchEvent.getX(), pSceneTouchEvent.getY()); 
       return true; 
      } 
      if(pSceneTouchEvent.isActionUp()){ 
       Log.e("Action UP", Boolean.toString(filler[fillerNum].active)); 
       createStationaryFiller(); 
      } 
     } 
    return false; 
} 

回答

1

只需保存UpdateHandler实例:

handler = new IUpdateHandler() {... etc 

和当你想停止它,请致电scene.unregisterUpdateHandler(handler)

+0

我想过这个,但我的isactionup从来没有注册(日志语句从不执行),这是我想要调用scene.unregisterUpdateHandler(处理程序),对吧? – rphello101

+0

TouchEvent在您抬起手指时甚至会触发吗?把一些日志输出放在if语句之前,然后看看。也许尝试检查pSceneTouchEvent.getAction()== MotionEvent.ACTION_UP。我认为这不会有帮助,但值得一试。 – JohnEye

+0

另外,记录pSceneTouchEvent.getAction()的值并告诉我你得到了什么。 – JohnEye

相关问题