Giter VIP home page Giter VIP logo

flame_spatial_grid's People

Contributors

asgalex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flame_spatial_grid's Issues

Cannot add JoystickComponent

I've been playing around with this package when I found a problem with JoystickComponent.
When I add it to any components like game, world or camera hud children, I got the following error:

'dart:ui/painting.dart': Failed assertion: line 5401 pos 12: '<optimized out>': is not true.
When the exception was thrown, this was the stack: 
#2      Canvas.drawImageRect (dart:ui/painting.dart:5401:12)
#3      Sprite.render (package:flame/src/sprite.dart:121:12)
#4      SpriteComponent.render (package:flame/src/components/sprite_component.dart:123:13)
#5      Component.renderTree (package:flame/src/components/core/component.dart:514:5)
#6      Transform2DDecorator.apply (package:flame/src/rendering/transform2d_decorator.dart:21:9)
#7      Decorator.applyChain (package:flame/src/rendering/decorator.dart:38:5)
#8      PositionComponent.renderTree (package:flame/src/components/position_component.dart:463:15)
#9      HasGridSupport.renderTree (package:flame_spatial_grid/src/components/has_grid_support.dart:222:13)

The error is a bit blurred (maybe because of this), but when we go to painting.dart:5401:12 we find this:

  void drawImageRect(Image image, Rect src, Rect dst, Paint paint) {
    assert(!image.debugDisposed); // <- here is the error

Any ideas on what's going on?
I'll be doing a few more tests this week.

Thanks!

Stuttering while building new cells

I created a simple setup with a moving player and I'm experiencing some stutter.
The joystick is present in the example just to help seeing the stutter with debug set to off, but it still stutters if you remove it and move the player in some other way. Debug mode off makes the stutter a lot weaker, but still present.

Is this an expected behavior in the current state of the project?

spatial_stutter.mov
import 'dart:async';

import 'package:flame/components.dart';
import 'package:flame/extensions.dart';
import 'package:flame/game.dart';
import 'package:flame/palette.dart';
import 'package:flame_spatial_grid/flame_spatial_grid.dart';

const _debugEnabled = true;

class MinimalGame extends FlameGame with HasSpatialGridFramework {
  MinimalGame();

  final world = MyWorld();
  late final CameraComponent cameraComponent;
  late final JoystickComponent joystick;

  @override
  FutureOr<void> onLoad() async {
    _createJoystick();

    final player = Player(position: Vector2.zero());

    cameraComponent = CameraComponent(
      world: world,
      hudComponents: [joystick, FpsTextComponent()],
    );
    cameraComponent.viewfinder.zoom = 1;
    cameraComponent.priority = 999;
    cameraComponent.follow(player, maxSpeed: 200, snap: true);

    await initializeSpatialGrid(
      cellSize: 50,
      rootComponent: world,
      trackedComponent: SpatialGridDebugCameraWrapper(cameraComponent),
      trackWindowSize: false,
      debug: _debugEnabled,
    );

    add(world);
    world.add(player);

    return super.onLoad();
  }

  void _createJoystick() {
    joystick = JoystickComponent(
      knob: CircleComponent(
        radius: 25,
        paint: BasicPalette.lightBlue.paint(),
      ),
      background: CircleComponent(
        radius: 100,
        paint: BasicPalette.blue.paint(),
      ),
      position: Vector2.all(100),
    );
  }
}

class SpatialGridDebugCameraWrapper extends SpatialGridCameraWrapper {
  SpatialGridDebugCameraWrapper(super.cameraComponent);

  @override
  void onAfterZoom() {
    try {
      if (!game.isSpatialGridDebugEnabled) {
        game.onAfterZoom();
      }
      // ignore: avoid_catches_without_on_clauses, empty_catches
    } catch (e) {}
  }
}

class Player extends PositionComponent
    with HasGridSupport, HasPaint, HasGameRef<MinimalGame> {
  Player({super.position})
      : super(
          size: Vector2(25, 25),
          anchor: Anchor.center,
        ) {
    paint.color = BasicPalette.yellow.color;
    debugMode = _debugEnabled;
  }

  late final _rect = Rect.fromLTWH(0, 0, size.x, size.y);

  @override
  void render(Canvas canvas) {
    canvas.drawRect(_rect, paint);
  }

  @override
  void update(double dt) {
    super.update(dt);
    if (!game.joystick.delta.isZero()) {
      position.add(
        game.joystick.relativeDelta * 100 * dt,
      );
    }
  }
}

class MyWorld extends World {}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.