I’m running a scene update handler to increase the scale of my sprite while the scene is being touched. It is supposed to stop when the user lifts his finger, but my action up never registers. The sprite just keeps increasing in size until the screen is touched again, at which point the old sprite stops growing and the new one starts. Any ideas why?
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*.5);
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()){
//Never executed
Log.e("Action UP", Boolean.toString(filler[fillerNum].active));
createStationaryFiller();
}
}
return false;
}
As it turns out, I needed to add an isActionUp method in the onAreaTouched method of the creation of my sprite as well as having it in the onSceneTouchEvent. Without the former, the sprites kept growing until another touch was added. Without the latter, you could drag your finger off of the sprite and it would still grow.