I want to make an If statement:
if(x == y+n)
{ }
n = [-20...20]
where n can be any integer value from -20 to 20.
How to do this in java?
In android I am trying to “synchronize” the ontouch listener to drawView. So I mean an image randomly appears I want to perform a certain action when the image appears….So the “touch” on the screen is pretty precise…
----DrawView Class---
setX(rand.nextInt(width-20));
setY(rand.nextInt(height-20));
canvas.drawBitmap(b, getX(), getY(), paint);
public boolean onTouch(View arg0, MotionEvent event) {
if (event.getX() == DrawView.getX()|| event.getY() == DrawView.getY())
{
Certian action...
}
}
so how can I include, DrawView.getX()+[-20…20] and DrawView.getY()+[-20…20]?
If I understand your question correctly, you might mean this:
For your specific range, you can simplify this expression by using
Math.abs: