As the title says, is there a method in libGDX which returns the touch pressure (similar to MotionEvent.getPressure() in Android) ?
Or is there any other way I can get touch pressure in my game which works on both android and iOS(using RoboVM)?
I can't help you with the iOS part
but for android there is a work around
you can do something like this to get the pressure
View view = initializeForView(game, config);
view.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
getInput().onTouch(v, event);
game.setPressure(event.getPressure());
Log.v("log", "hooked " + event.getPressure());
return true;
}
});
and still have the complete event handling of libgdx
Related
I'm working on an App with Android Studio(Java) and want a ScrollView inside a ScrollView.
If I scroll the small one to the end it automatically starts scrolling the big one, is it possibile to disable the scrolling function of the big one when scolling the small one?
You need to handle this by disabling the other ScrollView when scrolling the current one
Let's say you have scroll_view_parent and scroll_view_child
parentScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
findViewById(R.id.scroll_view_child).getParent()
.requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScrollView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
I may be asking a basic question, but to be honest, I have no real developement or code knowledge. I've been requested to make a prototybe of some basic app, that is supposed mainly to be buttons on screens, activable or disactivable.
I've been coding this on Android Studio 3.0, I (hardly) managed to place PNGs files on the screen, making it looking like a button. When I was pressing it, nothing happened of course, so I searched there and there how to make it change when pressed This worked
casedanger1.setOnTouchListener(new View.OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN :
casedanger1.setImageResource(R.drawable.casedanger1slct);
break;
case MotionEvent.ACTION_UP :
casedanger1.setImageResource(R.drawable.casedanger1);
break;
}
return false;
}
});
But when I try to disable again the button, it doesn't revert to the standard image (casedanger1)
How should I proceed ? I've been searching for days without a real solution. I have tried to make it a toggle button, which works, but makes the image bigger, and thus cropped.
Any hints that could help ? I'm really desperated, this is not something I'm familiar with.
Thank you
-Pliskin
I think you were close. Try this
casedanger1.setOnTouchListener(new View.OnTouchListener(){
// track if the image is selected or not
boolean isSelected = false;
public boolean onTouch(View v, MotionEvent event) {
if(isSelected) {
casedanger1.setImageResource(R.drawable.casedanger1slct);
} else {
casedanger1.setImageResource(R.drawable.casedanger1);
}
// toggle the boolean
isSelected = !isSelected;
return false;
}
});
I'm having a problem with my on touch listener - it works fine when the animation isn't running but wont work during the animation.
In case it is relevant the only method I'm using is the onFling() method.
I set up the touch listener and animation(to make an image view move down the screen):
image.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
and the Animation:
Animation moveDown = new TranslateAnimation(image.getX(), image.getX(), 0, pxHeight-pxImageHeight/2);
I have an onAnimationListener set up and have tried moving the onTouchListener to different parts of the code (such as onCreate, the onStart method of the animation and others)
In short, I want to be able to swipe my image during the animation of the imageView moving down the screen
Thanks
so pretty much i made a game that if you miss the target on screen the game is over, it works on my computer because it is a single click in a location but doesn't register on android because i feel like my finger is dragging by accident. i want the game to be over at the end of the drag in libgdx and am not sure how to go about it.
#Override
public boolean touchDragged(int screenX, int screenY, int pointer)
{
game.state = (GameState.GAMEOVER);
return false;
}
#Override
public boolean onTouch(View arg0, MotionEvent arg1) {
if(arg1.getAction() == MotionEvent.ACTION_DOWN) {
// This is what happens on the click down...
} else if(arg1.getAction() == MotionEvent.ACTION_UP) {
// this is what happens on the click release
return true;
}
return false;
}});
This would process the click if any of their motion is on the object and is based on release to vague first-engagement will be refined to further accuracy where they choose to remove their finger.
You just can't, because on android the touch drag method is called almost everytime, because your finger is still moving a little bit.. with the mouse you can keep it in the same place without problem..
But why you game should stop when the touch dragg is called?
To see if you miss your target on screen use a collision detection..
I'm trying to create a view programmatically, and change its background according to its click state.
I know I can do this with xml drawables, but I want to learn to program it too.
But if I press on my view, then slide my finger, the view gets stuck in pressed state. (white = 0xaaffffff background)
My code is this :
Edit:
I solved the problem. Here is the working code :
mainContainer.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
int action = event.getAction();
if (action==MotionEvent.ACTION_DOWN)
{
v.setBackgroundColor(0xaaffffff);
return false;
}
if(action==MotionEvent.ACTION_MOVE)
{
}
if(action==MotionEvent.ACTION_CANCEL)
{
v.setBackgroundColor(0x00ffffff);
}
if (action==MotionEvent.ACTION_UP)
{
v.setBackgroundColor(0x00ffffff);
return true;
}
return false;
}
});
As you see, I tried returning true wherever I want onTouch() to be called again. But apparently there is something I do not understand here.
What am I doing wrong ?
Thanks for any help.
What about returning true in your ACTION_UP aswell?
if (action==MotionEvent.ACTION_UP)
{
v.setBackgroundColor(0x00ffffff);
return true;
}