I have a runnable that I want to execute 4 times a second. Here is my runnable:
shoot = new Runnable() {
@Override
public void run() {
//Add bullet
parts.add(new Part(1, (int)(screenWidth*.01),
Part.TYPE_CIRCLE, (int)parts.get(activeShooter).center.x,
(int)parts.get(activeShooter).center.y));
parts.get(parts.size()-1).x_vel = (int)(Math.cos(parts.get(activeShooter).rotation)*bulletSpeed);
parts.get(parts.size()-1).y_vel = (int)(-Math.sin(parts.get(activeShooter).rotation)*bulletSpeed);
activeShooter = (activeShooter == numShooters) ? 0 : activeShooter + 1;
shooter.postDelayed(shoot, 250);
}
};
And here is my initial handler setup:
private void startBullets(){
Looper.prepare();
shooter = new Handler();
shooter.postDelayed(shoot, 250);
}
In all my other projects, I didn't have to call Looper.prepare but it throws an exception if I don't in this project. I don't know why. I basically copied a working code from another project (one that didn't require me to call Looper.prepare()). Can anyone see why my runnable isn't executing?