mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
merge stop option
This commit is contained in:
@ -1,9 +1,6 @@
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'components/component.dart';
|
||||
import 'flame.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flame/components/component.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
@ -13,51 +10,6 @@ abstract class Game {
|
||||
|
||||
void render(Canvas canvas);
|
||||
|
||||
start() {
|
||||
var previous = Duration.ZERO;
|
||||
|
||||
window.onBeginFrame = (now) {
|
||||
var recorder = new PictureRecorder();
|
||||
var canvas = new Canvas(
|
||||
recorder,
|
||||
new Rect.fromLTWH(
|
||||
0.0, 0.0, window.physicalSize.width, window.physicalSize.height));
|
||||
|
||||
Duration delta = now - previous;
|
||||
if (previous == Duration.ZERO) {
|
||||
delta = Duration.ZERO;
|
||||
}
|
||||
previous = now;
|
||||
|
||||
var t = delta.inMicroseconds / Duration.MICROSECONDS_PER_SECOND;
|
||||
|
||||
update(t);
|
||||
render(canvas);
|
||||
|
||||
var deviceTransform = new Float64List(16)
|
||||
..[0] = window.devicePixelRatio
|
||||
..[5] = window.devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
|
||||
var builder = new SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(Offset.zero, recorder.endRecording())
|
||||
..pop();
|
||||
|
||||
window.render(builder.build());
|
||||
window.scheduleFrame();
|
||||
};
|
||||
|
||||
window.scheduleFrame();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class GameWidget {
|
||||
void update(double t);
|
||||
|
||||
void render(Canvas canvas);
|
||||
|
||||
Widget _widget;
|
||||
|
||||
Widget get widget {
|
||||
@ -72,7 +24,7 @@ abstract class GameWidget {
|
||||
}
|
||||
|
||||
class GameRenderObjectWidget extends SingleChildRenderObjectWidget {
|
||||
GameWidget game;
|
||||
Game game;
|
||||
|
||||
GameRenderObjectWidget(this.game);
|
||||
|
||||
@ -84,7 +36,7 @@ class GameRenderObjectWidget extends SingleChildRenderObjectWidget {
|
||||
class GameRenderBox extends RenderBox {
|
||||
BuildContext context;
|
||||
|
||||
GameWidget game;
|
||||
Game game;
|
||||
|
||||
int _frameCallbackId;
|
||||
|
||||
@ -147,15 +99,8 @@ class GameRenderBox extends RenderBox {
|
||||
}
|
||||
|
||||
class BaseGame extends Game {
|
||||
|
||||
List<Component> components = new List();
|
||||
|
||||
@override
|
||||
void start() {
|
||||
Flame.initialize();
|
||||
super.start();
|
||||
}
|
||||
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
canvas.save();
|
||||
|
||||
@ -28,11 +28,7 @@ class Util {
|
||||
});
|
||||
}
|
||||
|
||||
Paragraph text(String text,
|
||||
{double fontSize = 24.0,
|
||||
Color color = Colors.white,
|
||||
fontFamily: 'Arial',
|
||||
double maxWidth = 180.0}) {
|
||||
Paragraph text(String text, { double fontSize = 24.0, Color color = Colors.white, fontFamily: 'Arial', double maxWidth = 180.0 }) {
|
||||
ParagraphBuilder paragraph = new ParagraphBuilder(new ParagraphStyle());
|
||||
paragraph.pushStyle(new ui.TextStyle(
|
||||
color: color, fontSize: fontSize, fontFamily: fontFamily));
|
||||
@ -41,6 +37,10 @@ class Util {
|
||||
..layout(new ParagraphConstraints(width: maxWidth));
|
||||
}
|
||||
|
||||
void enableEvents() {
|
||||
window.onPlatformMessage = BinaryMessages.handlePlatformMessage;
|
||||
}
|
||||
|
||||
void addGestureRecognizer(GestureRecognizer recognizer) {
|
||||
GestureBinding.instance.pointerRouter.addGlobalRoute((PointerEvent e) {
|
||||
if (e is PointerDownEvent) {
|
||||
@ -48,5 +48,4 @@ class Util {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user