Olá amigos, estou desenvolvendo um jogo, e me deparei com um problema que esta complicado de resolver....
estou criando um healthBar para visualizar a vida dos monstros criados. COnsegui adicionar o abençoado com o metodo canvas.drawRect.
Só que tem um problema, ao movimentar o personagem, o mesmo nao fica atrelado ao monstro, ele sai andando por ai 😞
Vou disponilizar um pouquinho do que estou fazendo...
public void draw(Canvas canvas, GameDisplay gameDisplay) {
float width = 80;
float height = 15;
float margin = 2;
float x = (float) gameDisplay.gameToDisplayCoordinatesX(positionX)-100;
float y = (float) gameDisplay.gameToDisplayCoordinatesY(positionY);
float distanceToPlayer = 75;
// draw circle
canvas.drawCircle(
(float) gameDisplay.gameToDisplayCoordinatesX(positionX),
(float) gameDisplay.gameToDisplayCoordinatesY(positionY),
(float) radius,
paint
);
// Draw border
float borderLeft, borderTop, borderRight, borderBottom;
borderLeft = x - width / 2;
borderRight = x + width / 2;
borderBottom = y - distanceToPlayer;
borderTop = borderBottom - height;
canvas.drawRect(
(float) gameDisplay.gameToDisplayCoordinatesX(borderLeft),
(float) gameDisplay.gameToDisplayCoordinatesY(borderTop),
(float) gameDisplay.gameToDisplayCoordinatesX(borderRight),
(float) gameDisplay.gameToDisplayCoordinatesY(borderBottom),
borderPaint);
// Draw health
float healthLeft, healthTop, healthRight, healthBottom, healthWidth, healthHeight;
healthWidth = width - 2 * margin;
healthHeight = height - 2 * margin;
healthLeft = borderLeft + margin;
healthRight = healthLeft + healthWidth * 1;
healthBottom = borderBottom - margin;
healthTop = healthBottom - healthHeight;
canvas.drawRect(
(float) gameDisplay.gameToDisplayCoordinatesX(healthLeft),
(float) gameDisplay.gameToDisplayCoordinatesY(healthTop),
(float) gameDisplay.gameToDisplayCoordinatesX(healthRight),
(float) gameDisplay.gameToDisplayCoordinatesY(healthBottom),
healthPaint);
}
No codigo acima eu crio um circulo e depois coloco a barra acima do circulo... Mas ao andar com o joystick a barra se separa do circulo, como "unifica-los" para andarem juntos?
ao monstro andar, a barra fica perfeita, se movimenta pelo mapa sobre o monstro, más ao movimentar o joystick ela se movimenta de acordo com o player...