mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
feat: FlameIsolate - a neat way of handling threads (#1909)
Adding a bridge library for integral_isolates adding support for components to run CPU intensive code with a function similar to Flutter's compute function, but with a long lived isolate. Lifecycle is handled by the game loop, where the isolate would live between onMount and onRemove.
This commit is contained in:
24
packages/flame_isolate/example/lib/terrain/grass.dart
Executable file
24
packages/flame_isolate/example/lib/terrain/grass.dart
Executable file
@ -0,0 +1,24 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_isolates_example/terrain/terrain.dart';
|
||||
|
||||
class Grass extends PositionComponent with Terrain {
|
||||
static final _color = Paint()..color = const Color(0xff567d46);
|
||||
static final _debugColor = Paint()..color = Colors.black.withOpacity(.5);
|
||||
|
||||
late final _rect = size.toRect();
|
||||
late final _rect2 = Rect.fromCenter(
|
||||
center: _rect.center,
|
||||
height: 10,
|
||||
width: 10,
|
||||
);
|
||||
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
canvas.drawRect(_rect, _color);
|
||||
canvas.drawRect(_rect2, _debugColor);
|
||||
}
|
||||
|
||||
@override
|
||||
double difficulty = 1.0;
|
||||
}
|
||||
Reference in New Issue
Block a user