I've recently added an explosion in my game, for when enemies get killed, and it works fine and all, but the explosion wont "spawn" on the enemies x
and y
.
The problem is that I'm not drawing the bitmap from the center, but from its 0,0
position, so the explosion spawns at my enemies 0,0
.
It's not like the explosion spawns at random places, it spawns around the enemies bitmap, but just not on the center, and it is really annoying to look at.
But if I try to change it so I add them at the center, It creates a really weird effect when rotating them that is hard to explain.
I cant use this: canvas.drawBitmap(bitmap, x - bitmap.getWidth/2, y - bitmap.getHeight/2, null);
, or I'm just doing it wrong and missing something.
How I draw my enemies:
public void draw(Canvas canvas) {
canvas.save();
canvas.rotate((float) rotater, x + (width / 2), y + (height/2));
int srcX = currentFrame * width;
int srcY = 0 * height;
Rect src = new Rect(srcX, srcY, srcX + width, srcY + height);
Rect dst = new Rect(x, y, x + width, y + height);
canvas.drawBitmap(bitmap, src, dst, null);
canvas.restore();
}
How I add my explosions:
if (enemies.get(i).getHP() <= 0) { //enemy death
addExplosion(enemies.get(i).getX(), enemies.get(i).getY());
If you need any more info to be able to help, let me know. Thank you!