1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Problem calculating correct position in Flame Game Component Render() override

Discussão em 'Mobile' iniciado por Stack, Outubro 5, 2024 às 11:53.

  1. Stack

    Stack Membro Participativo

    I have a custom flame game TextComponent and I want to draw extra stuff in the render override. I’m using 4 different formulas to calculate the position but each try is wrong. None of these formulas calculates a circle position that stays glued to the moving text. Instead they move as if some scale factor was involved. Any ideas what I’m doing wrong?

    void render(Canvas canvas) {
    super.render(canvas);

    canvas.drawCircle(Offset(position.x, position.y), 10, redPaint);

    Vector2 pos = position / scale.x;
    Component? parent = this.parent;
    while (parent != null) {
    if (parent is PositionComponent) {
    pos -= parent.position / parent.scale.x;
    }
    parent = parent.parent;
    }

    canvas.drawCircle(Offset(pos.x, pos.y), 10, yellowPaint);

    canvas.drawCircle(
    Offset(absolutePosition.x / absoluteScale.x, absolutePosition.y / absoluteScale.y),
    10,
    bluePaint);

    canvas.drawCircle(Offset(position.x / scale.x, position.y / scale.y), 10, greenPaint);
    }

    Continue reading...

Compartilhe esta Página