mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 03:15:43 +08:00
todo, fullscreen
This commit is contained in:
@ -6,11 +6,9 @@ import 'package:flutter/painting.dart';
|
||||
import 'flame.dart';
|
||||
|
||||
abstract class Component {
|
||||
|
||||
void update(double t);
|
||||
|
||||
void render(Canvas c);
|
||||
|
||||
}
|
||||
|
||||
abstract class PositionComponent extends Component {
|
||||
@ -25,11 +23,9 @@ abstract class PositionComponent extends Component {
|
||||
double distance(PositionComponent c) {
|
||||
return sqrt(pow(this.y - c.y, 2) + pow(this.x - c.x, 2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
abstract class SpriteComponent extends PositionComponent {
|
||||
|
||||
double width, height;
|
||||
Image image;
|
||||
|
||||
@ -46,21 +42,28 @@ abstract class SpriteComponent extends PositionComponent {
|
||||
}
|
||||
|
||||
render(Canvas canvas) {
|
||||
if (image != null) {
|
||||
_prepareCanvas(canvas);
|
||||
_drawImage(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
void _prepareCanvas(Canvas canvas) {
|
||||
canvas.translate(x, y);
|
||||
canvas.rotate(angle); // TODO: rotate around center
|
||||
if (image != null) {
|
||||
final Rect outputRect = new Rect.fromLTWH(0.0, 0.0, width, height);
|
||||
|
||||
final Size imageSize = new Size(
|
||||
image.width.toDouble(), image.height.toDouble());
|
||||
final FittedSizes sizes = applyBoxFit(
|
||||
BoxFit.cover, imageSize, outputRect.size);
|
||||
final Rect inputSubrect = Alignment.center.inscribe(
|
||||
sizes.source, Offset.zero & imageSize);
|
||||
final Rect outputSubrect = Alignment.center.inscribe(
|
||||
sizes.destination, outputRect);
|
||||
canvas.drawImageRect(image, inputSubrect, outputSubrect, paint);
|
||||
}
|
||||
|
||||
void _drawImage(Canvas canvas) {
|
||||
final Rect outputRect = new Rect.fromLTWH(0.0, 0.0, width, height);
|
||||
final Size imageSize =
|
||||
new Size(image.width.toDouble(), image.height.toDouble());
|
||||
final FittedSizes sizes =
|
||||
applyBoxFit(BoxFit.cover, imageSize, outputRect.size);
|
||||
final Rect inputSubrect =
|
||||
Alignment.center.inscribe(sizes.source, Offset.zero & imageSize);
|
||||
final Rect outputSubrect =
|
||||
Alignment.center.inscribe(sizes.destination, outputRect);
|
||||
canvas.drawImageRect(image, inputSubrect, outputSubrect, paint);
|
||||
}
|
||||
|
||||
update(double t) {}
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'dart:ui' as ui show TextStyle;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class Util {
|
||||
Future<Size> initialDimensions() async {
|
||||
// https://github.com/flutter/flutter/issues/5259
|
||||
@ -29,13 +28,21 @@ class Util {
|
||||
new _CustomBinder();
|
||||
}
|
||||
|
||||
Paragraph text(String text, { double fontSize = 24.0, Color color = Colors.white, fontFamily: 'Arial', double maxWidth = 180.0 }) {
|
||||
void fullScreen() {
|
||||
SystemChrome.setEnabledSystemUIOverlays([]);
|
||||
}
|
||||
|
||||
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));
|
||||
paragraph.pushStyle(new ui.TextStyle(
|
||||
color: color, fontSize: fontSize, fontFamily: fontFamily));
|
||||
paragraph.addText(text);
|
||||
return paragraph.build()..layout(new ParagraphConstraints(width: maxWidth));
|
||||
}
|
||||
}
|
||||
|
||||
class _CustomBinder extends BindingBase with ServicesBinding {
|
||||
}
|
||||
class _CustomBinder extends BindingBase with ServicesBinding {}
|
||||
|
||||
Reference in New Issue
Block a user