Skip to main content
added 22 characters in body
Source Link
petervaz
  • 1k
  • 3
  • 13
  • 31

Try something like this (this is pseudocode, I don't know your objects actual fields)

1 - determine the enemy's center.

centerX = xenemy.getX() + (enemy.getWidth() /2 );
centerY = yenemy.getY() + (enemy.getHeight() / 2);

2 - assume the center of the explosion is the same center of the enemy and determine that explosion top-left from its size

explosion.setX(centerX - (explosion.getWidth() / 2);
explosion.setY(centerY - (explosion.getHeight() / 2);

Try something like this (this is pseudocode, I don't know your objects actual fields)

1 - determine the enemy's center.

centerX = x + (enemy.getWidth() /2 );
centerY = y + (enemy.getHeight() / 2);

2 - assume the center of the explosion is the same center of the enemy and determine that explosion top-left from its size

explosion.setX(centerX - (explosion.getWidth() / 2);
explosion.setY(centerY - (explosion.getHeight() / 2);

Try something like this (this is pseudocode, I don't know your objects actual fields)

1 - determine the enemy's center.

centerX = enemy.getX() + (enemy.getWidth() /2 );
centerY = enemy.getY() + (enemy.getHeight() / 2);

2 - assume the center of the explosion is the same center of the enemy and determine that explosion top-left from its size

explosion.setX(centerX - (explosion.getWidth() / 2);
explosion.setY(centerY - (explosion.getHeight() / 2);
Source Link
petervaz
  • 1k
  • 3
  • 13
  • 31

Try something like this (this is pseudocode, I don't know your objects actual fields)

1 - determine the enemy's center.

centerX = x + (enemy.getWidth() /2 );
centerY = y + (enemy.getHeight() / 2);

2 - assume the center of the explosion is the same center of the enemy and determine that explosion top-left from its size

explosion.setX(centerX - (explosion.getWidth() / 2);
explosion.setY(centerY - (explosion.getHeight() / 2);