Let's say that I have a cannon on the bottom of the screen that shoots balls to the click direction. I also have some collisions algorithms and here comes the problem. I am trying to implement an OnHold method that shoots continously and it works, but I think that I need to make shooting on another Thread. I've implemented this in two ways: 1. I was checking the delay and if it passed I shot 2. I was checking previous ball y position and when it floated away I shot
The problem comes here that when I hold the button for some time, for example. 5 balls are okay (they're near each other - not colliding) and then comes a ball that is late O.o
I don't know how to implement a new Thread within these MotionEvents. If is there someone who can point me (if should I make in on Threads or something) a solution - I would be grateful :)
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
touched_x = event.getX();
touched_y = event.getY();
int i = 100;
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
startShootTime = new Date().getTime();
running = true;
} else if (action == MotionEvent.ACTION_MOVE ) {
shootTime = new Date().getTime();
// movement: cancel the touch press
running = true;
touched_x = event.getX();
touched_y = event.getY();
// && game.gameLoop.current_time - shootTime > 400 &&
// game.gameLoop.current_time - startShootTime > 100
// while(actionUpflag) {
int size = game.gameLoop.balls.size();
if(size == 0){
game.gameLoop.balls.add(new Ball(metrics.widthPixels, metrics.heightPixels, touched_x, touched_y, game.gameLoop.ball_bmp_width, metrics.heightPixels-game.gameLoop.ball_bmp_width/2));
}else if(size > 0 && game.gameLoop.balls.get(size-1).image_center_y < metrics.heightPixels - game.gameLoop.ball_bmp_width-50)
game.gameLoop.balls.add(new Ball(metrics.widthPixels, metrics.heightPixels, touched_x, touched_y, game.gameLoop.ball_bmp_width, metrics.heightPixels-game.gameLoop.ball_bmp_width/2));
invalidate(); // request draw
} else if (action == MotionEvent.ACTION_UP) {
running = false;
}
return true;
}