OpenGL sprite looses focus on fast move - android

I'm making simple app where user can move squares with finger on screen. First I'm checking if touch coords are on square to allow the move. Then square is moving along GLSurfaceView#onTouchEvent event coordinates.
It works OK. But when finger is moving too quick (like swipe) square looses the focus and stays still. It seems that OpenGL renders square after the move event occurs, so coordinates check fail.
Please point some keywords to figure out the question (googling gives same links again and again) or some docs. Thanks.

You need hold focus on sprite. If sprite got event "down" it holds focus until doesn't get "up" or "cancel" event. So, while sprite holds focus all touch events send to it.

Related

pygame - link an object to mouse event

I am trying to develop a game for Android using pygame.
It would be a platformer. To move the main charachter, I would make the game to wait for mouse events (like pygame.MOUSEBUTTONDOWN).
In order to do that on mobile, I'd like to create a graphic representation of a joypad with arrow keys to be shown on the bottom left corner of the screen.
Now, when the user touches one of the arrows, a MOUSEBUTTONDOWN event should be triggered and the charachter should move accordingly.
My question is: since the "joypad" object is a mere draw, how can I link it to the event with pygame?
Is there a way to do so? Should I use the pixel coordinates of the arrow keys of the joypad or is there a better choice?
As far as I know this is not possible.
When handling input, mouse input and touch input are to be handled separately.
So to answer the 2 questions you listed at the end:
As far as I know there is no way to implement this functionality.
You could use the pixel coordinates of the arrows. However you can use Rects for that and test if the place of mouse input/touch input is inside the arrow button Rect with the collidepoint method
You can achieve that as follows:
arrow_left.collidepoint(mouse_x, mouse_y)
I hope this answer helped you!

have textview change style/attribute on touch roll-off

Ok, I simply can't figure this out for the life of me. I created a custom textview and I basically want it to be a button. I have all my code working except that I can't get it to detect when touched, and then the touch event rolls out of its boundary. Say the textview lights up grey when touched, then if the user drags their finger away to the left or right, I want to have the grey disappear and reset to its normal background color.
I realize I can just use the standard android button, but I don't like how it delays on changing color for the touch event. Maybe someone knows where the stock Button.java class code is, for the android API so I can look at that for hints?
I have tried getting the dimensions of the button with an on global listener and then tracking user touch events to be within those dimensions. And the dimensions and touch location are reported correctly and works sometimes, but it simply doesn't work reliably, maybe due to the user moving too quickly, for example. Even if I set the touch boundary a few pixels inside of the actual boundary.

Andengine sprite touch event on layers

I am developing a game using AndEngine in which on the game screen i have 2 layers - backlayer and frontlayer. On the backlayer i have attached 1 player sprite and several baddies sprite. On the frontlayer i have attached a tree sprite. Now what i want is that the baddies move around the screen in a zig-zag way throughout the game and when the user touches the baddie, they will be popped(disappear/detached) but when they go behind the tree they should not be popped when the user touches the tree on the area where baddie is but not visible.
I have transparent background for the image of tree and since there are several region in the tree where there are no leaves so that area is also transparent and the baddies are visible in that region and also they can be popped in that region.
I am done with all the stuffs, only the problem I face is baddies are popped even when they are behind the tree and not visible to the user.
Kindly please help me...
If you know when they are back in the tree, then disable the touch area for that sprite or do nothing when touched if they are back.
You can make use of PixelPerfectSprite where it will return true only if you are touching the tree, and will return false if you are touching in between leaves (i.e in transparent region)
After this if your fingure is colliding with tree as well as your character then don't pop up else if it collides only character then pop up

dispatching touch events

I have 12 horoscope sign images which are placed in 360 degree circular position. ImageButtons are being used to display the horoSignImages. ImageButton has selector that show pressed and unpressed states for horosSignImage. The signWheel rotates by using gestuer.
Problem is that, When i tap right over the horosignImage to rotate the wheel, the imageButton catches the event and wheel is not rotated upon scrolling the finger. I want to animate the image its pressed state when the user taps right over it, meanwhile the wheel should rotate if the user scrolls his finger. Wheel rotation only works if i tap outside the horosignImage and scroll the finger.
Any suggestions to solve this problem?
Sadly I don't have the answer, but your problem seems to be similar to Passing touch events to the parent view
In both cases you want the touch event handled by the imageButton as well as the signWheel.

How to get the direction of the finger in android game

I am trying to develop a game with Android where I need to move a tile in all directions. My question is how can I get the motion of the finger on the screen(right,left,top) using getX() and getY()?
Thanks.
Take a look at getHistoricalSize, getHistoricalX(int) and getHistoricalY(int).
When the finger is touching the screen, Android records the move positions and saves them. You can then call getHistorySize to get the number of motions recorded, and then call getHistoricalX and getHistoricalY with a parameter less that the history size to get the x/y at that history position.
So, for example, you can call getHistoricalY with a parameter that indicates that previous motion event, and then compare it to the current one. If the current one is bigger, then the finger is swiping down.
Note: Motion events recording applies only to ACTION_MOVE.

Categories

Resources