Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generateValues not being triggered[Bug]: #474

Closed
arnovanzyl opened this issue Nov 22, 2023 · 2 comments
Closed

generateValues not being triggered[Bug]: #474

arnovanzyl opened this issue Nov 22, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@arnovanzyl
Copy link

What happened?

It seems that with version 3.0.9 the generateValues function is no longer being triggered.

Steps to reproduce?

import 'package:bonfire/bonfire.dart';
import 'package:flame_audio/flame_audio.dart';
import 'package:get/get.dart';
import 'package:platformer/characters/player/common_sprite_sheet.dart';
import 'package:platformer/services/user_settings_service/service/user_settings_service.dart';

class PotionLife extends GameDecoration
    with Sensor<Player>, Movement, HandleForces, BlockMovementCollision {
  final double life;
  double _lifeDistributed = 0;

  PotionLife(Vector2 position, this.life, {Vector2? size})
      : super.withAnimation(
          animation: CommonSpriteSheet.potionLifeSprite,
          position: position,
          size: size ?? Vector2.all(8),
        );

  @override
  void onContact(Player component) {
    generateValues(
      const Duration(seconds: 1),
      onChange: (value) {
        if (_lifeDistributed < life) {
          double newLife = life * value - _lifeDistributed;
          _lifeDistributed += newLife;
          component.addLife(newLife.roundToDouble());
        }
      },
    );
    UserSettingsService userSettingsService = Get.find();
    FlameAudio.play(
      'effects/pickup_sound.wav',
      volume: userSettingsService.userSettings.value.effectVolume,
    );
    removeFromParent();
    super.onContact(component);
  }

  @override
  Future<void> onLoad() {
    renderAboveComponents = true;
    priority = 3;
    debugMode = false;
    add(
      RectangleHitbox(
        size: Vector2(size.x, size.y),
        anchor: Anchor.topLeft,
        isSolid: true,
      ),
    );
    return super.onLoad();
  }
}

What did you expect to happen?

In version 3.0.6 the following game object worked, however since then it seems that the generateValues function is no longer being triggered

Bonfire version

Release 3.0.9

Relevant log output

No response

@arnovanzyl arnovanzyl added the bug Something isn't working label Nov 22, 2023
@RafaelBarbosatec
Copy link
Owner

Fixed in version 3.0.10
Please use gameRef. generateValues when you need remove the current component.
When you use generateValues, it will be removed together with component.

@arnovanzyl
Copy link
Author

Thanks Rafael!!! Always appreciate the brilliant work! 🥳😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants