Else statement being executed after if statement is satisfied
I am using AndEngine to develop my game, though I'm thinking this problem
is unrelated to AndEngine.
I have two possible dialogs that fire if:
User touches down in an incorrect area or
Users lifts up from an incorrect area.
Unfortunately, if a user touches down in an incorrect area, when they lift
up they are also satisfying error 2--lifting up from an incorrect area.
Here's my code in a nutshell:
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
float y = pSceneTouchEvent.getY();
int dialog_count = 0;
if (pSceneTouchEvent.isActionDown() && y < 1000) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog Code
..............
}
}
dialog_count ++;
Log.d("Dialog Count", "Count is " + dialog_count);
} else if (dialog_count < 1 && pSceneTouchEvent.isActionUp() && y > 105) {
Log.d("Dialog Count", "Count is still " + dialog_count);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Second AlertDialog Code
.................
}
}
return false;
}
Now, my first log for dialog_count shows a value of 1. However when I lift
up the second log shows a value of 0. Somehow this value is either getting
reset or my Else statement just can't see the updated value of
dialog_count because I get the second dialog popping on top of my first.
Any ideas?
No comments:
Post a Comment