asgalex / flame_spatial_grid Goto Github PK
View Code? Open in Web Editor NEWExperimental API to improve Flame performance on huge or even infinite maps
License: MIT License
Experimental API to improve Flame performance on huge or even infinite maps
License: MIT License
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!
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?
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 {}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.