Android multitouch strange bug when touch point reach limit - java

I am make a application on android that need multi-touch gesture! I found that my devices Novo 7 (ainol) supports 5 touch points. I implement onTouch for a View like this
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN || event.getAction() == MotionEvent.ACTION_DOWN){
Log.i("Touch", "Touch "+event.getPointerCount() + " -- Position " +
event.getRawX()+","+event.getRawY());
}
else if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_UP|| event.getAction() == MotionEvent.ACTION_UP){
Log.i("Touch up","Pointer = "+event.getPointerCount());
}
return true;
}
At first, everything is ok, the log is printed out perfectly with 5 message. But things happened when i touch and release the 6th point on screen. The log re-printed out 5 message. Can you tell me what is going on here. Sorry for my bad english and if this is a noob question! Thank you very much!
----------- EDITED--------------------
After logging for ACTION_POINTER_UP and ACTION_UP, i found out that when the 6th finger touch (touch down) the screen, all the current pointers (5 pointers) is release from the Event (e.g the action_up and action_pointer_up is call on 5 previous pointers)! Now, the question is, how the android process this situation when the limitation of touch point is reach.

Related

Android: onTouchEvent breaks

i am creating an android game and have an onTouchEvent like this:
#Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (!action) {
action = true;
}
} else {
action=false;
}
return true;
}
My problen is now, that action is false as soon as i swipe my finger a little bit.
thanks for helping,
Florian
If you want to return true even when a swipe input occurs, you could store the last action to compare if the last action was ACTION_DOWN and if the current 'event.getAction()' is also ACTION_DOWN, then you can assume that the swipe action occurs (also if the previous 'x' and 'y' positions differ to the current 'x' and 'y' positions), therefore still return true. Any other scenario, you can return false.
You could also try looking in the android API documentation about a swipe input action/gesture.
Hope that is helpful.

JavaFX KeyCode for constant MINUS

I'm using Eclipse. I developed simple JavaFX calculator app, everything is working but keyevent for numpad MINUS and PLUS. Which is funny because every other numpad key is ok. Am I missing something?
public void onKeyPress(KeyEvent event) {
KeyCode keyCode = event.getCode();
Just a piece of my code:
case PLUS:
if (operation.getOperand() == 'x') {
operation.add(Double.parseDouble("" + display.getText()), display);
decimal.setDisable(false);
} else {
result.fire();
operation.add(Double.parseDouble("" + display.getText()), display);
decimal.setDisable(false);
}
break;
Just now i thought of debugging keycodes themselves while running the app. Added a simple console output of a keycode that is currently pressed, found out that constant for numpad plus and minus in not PLUS and MINUS but ADD and SUBTRACT.
Thanks to all who took the time to answer me.

How to create an enemy that you defeat by tapping as it falls from the top of the screen?

I am making a game using android eclipse(java) where enemies fall from the top of the screen to the bottom. I have succeeded in making them fall (a little too fast but good enough for now) but I have not been able to make them respond correctly to tapping. At first, all enemies were defeated wherever the touch occurred but now there is no response at all. My question is how do i correctly read the player input. Thanks to anyone who reads this. This is my first post so I apologize if the question was posed incorrectly.
public boolean onTouchEvent(MotionEvent e) {
switch (e.getAction() & MotionEvent.ACTION_MASK) {
// Player has touched the screen
case MotionEvent.ACTION_DOWN:
paused = false;
// Has the player tapped an alien
for (int i = 0; i < enemyNumb; i++) {
if (aliens[i].getVisibility() & aliens[i].getX() == e.getX() & aliens[i].getY() == e.getY()) { // Enemy defeated code goes here
Okay, I got it to work by using a box to detect a click within. This is what i used before but the aliens were put into the same box so they all disappeared and it made me believe that it was wrong. Thank you cricket_007 for the suggestion.
if ( aliens[i].getRect().contains(e.getX(), e.getY()))

Timed display for graphic button on action_down MotionEvent

So I have spent a long time looking to see if there is a solution for this. Basically, the below code allows me to press on a button, when I press (action_down) the 'pressed version' of the button is displaying good, then when I remove my finger the graphic returns to normal (action_up).
This part is working good BUT I need the ACTION_DOWN to stay active a little longer after the user presses the button and not return to ACTION_UP so fast. I can see lots of different people asking this question but no answers relating to editing the action_up or action_down part. I thought there must be some simple way to achieve this goal..
The current code:
#Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEvent.ACTION_DOWN == event.getAction()) {
int img = Integer.parseInt(v.getTag(R.id.tag_press_down_img).toString());
if (v instanceof ImageView) {
((ImageView) v).setImageResource(img);
}
} else if (MotionEvent.ACTION_UP == event.getAction()) {
int img = Integer.parseInt(v.getTag(R.id.tag_press_up_img).toString());
if (v instanceof ImageView) {
((ImageView) v).setImageResource(img);
}
}
return false;
}
(This code is working fine but the user experience is bad because the button reverts back to ACTION_UP too fast (immediately) after being released - I would like ACTION_DOWN to 1) display for 1-2 seconds then revert back to ACTION_UP OR 2) remain in action_down until the called event is complete - in this case loading another screen).
Thank you!

small lags when starting the next moveTo action

[UPDATE] i changed the order a bit so i call the super.act(delta) at the end of the method and it seems to help a bit! But not that sure about it yet.
I got a square system for my map. So its an 2D array and i i make one move the figure does move from one square to the next. While that it's not possible to "stop" the figure between 2 squares. When my characters made one move i check if the Touchpad is touched and if yes i start the next move. While that it seems to lag sometimes and i dont know why!? I really hope you may find the "lag". Here is how i calculate the next move inside the act()of my Actor Character:
#Override
public void act(float delta) {
super.act(delta); // so the actions work
if (moveDone) {
if (screen.gameHud.pad.isTouched()) {
// check in which direction is the touchcontroller
if (screen.gameHud.pad.getKnobPercentX() < 0
&& Math.abs(screen.gameHud.pad.getKnobPercentY()) < Math
.abs(screen.gameHud.pad.getKnobPercentX())) {
// checkt if the |x|>|y|
if (checkNextMove(Status.LEFT)) {
this.status = Status.LEFT;
move(Status.LEFT);
this.screen.map.mapArray[(int) (this.mapPos.x)][(int) this.mapPos.y] = Config.EMPTYPOSITION;
this.screen.map.mapArray[(int) (this.mapPos.x - 1)][(int) this.mapPos.y] = Config.CHARSTATE;
this.mapPos.x--;
moveDone = false;
}
} else if //.... rest is the same just with other directions
else{ //if touchpad isnt touched!
setIdle();
}
updateSprite(delta); //just change the textureRegion if its time for that
} //methode end
Okay so you need some more informations i am sure. Checkmoves like this:
case LEFT:
if (this.mapPos.x - 1 >= 0)
if (this.screen.map.mapArray[(int) (this.mapPos.x - 1)][(int) this.mapPos.y] == Config.EMPTYPOSITION)
return true;
break; //same for all other just direction changin
And the last you need to know is the move(_) i guess. It does add an moveTo Action to my figures.
public void move(Status direction) {
switch (direction) {
case LEFT:
this.addAction(Actions.sequence(
Actions.moveTo((getX() - Config.BLOCK_SIZE), getY(), speed),
moveDoneAction));
break;
moveDoneAction is a simple RunnableAction that set the boolean moveDone to true if its done moving.
i really hope you can help. If you need some more informations please let me know as comment!
There are better tools than StackOverflow for optimizing Android code. Use a profiler and see what is actually happening. Specifically, the traceview profiler: how to use traceview in eclipse for android development? (If you're not using Eclipse, you can use traceview directly via the ADT.)

Categories

Resources