# translating canvas for rotating sprites that shoot

I am trying to align bullets to my different sprites guns (top down 2D for android). Right now Im using this method to draw my bullets:

public void draw(Canvas canvas){
update();
canvas.save();
canvas.rotate(angle, x + width / 2, y + height / 2);
canvas.translate(translaterX, translaterY);
canvas.drawBitmap(bitmap, x, y, null);
canvas.restore();
}


The problem here is the translater, Im always having to add or substract from it to make the bullets spawn from my gun when my sprites rotate and I cant figure it out, is there any standard value for this, like translaterX = bitmap.getwidth()/2? I dont really understand how the translater works and I feel like Ive tried everything, what am I missing? For the examples sake lets say that my gun is always in the middle of the bitmap.

Or is there even another way to do this that is simpler?

• I it not obvious what you whant, or what your code should de. For example what are the variables: translaterX, translaterY, bitmap, x, y. Where do they come from, what do they store? – Arne Jan 19 '14 at 19:17

you'll need to calculate the rotation of the gun from the center of the player sprite

x = (float)Math.cos(playerAngle) * radius;