我正在尝试使用更新处理程序来增加精灵的比例。但是,它不允许调用场景动作up事件,因此精灵的大小会继续增加。如何在操作启动时让更新处理程序中断?这就是我所拥有的:
更新处理程序:
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;
}
答案 0 :(得分:1)
只需保存UpdateHandler的实例:
handler = new IUpdateHandler() {... etc
如果您想停止播放,请拨打scene.unregisterUpdateHandler(handler)