mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 11:43:19 +08:00
todo, fullscreen
This commit is contained in:
1
TODO.md
1
TODO.md
@ -1,4 +1,5 @@
|
|||||||
TODO:
|
TODO:
|
||||||
|
|
||||||
* Rotation around sprint center
|
* Rotation around sprint center
|
||||||
|
* Cache images
|
||||||
|
|
||||||
@ -6,11 +6,9 @@ import 'package:flutter/painting.dart';
|
|||||||
import 'flame.dart';
|
import 'flame.dart';
|
||||||
|
|
||||||
abstract class Component {
|
abstract class Component {
|
||||||
|
|
||||||
void update(double t);
|
void update(double t);
|
||||||
|
|
||||||
void render(Canvas c);
|
void render(Canvas c);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class PositionComponent extends Component {
|
abstract class PositionComponent extends Component {
|
||||||
@ -25,11 +23,9 @@ abstract class PositionComponent extends Component {
|
|||||||
double distance(PositionComponent c) {
|
double distance(PositionComponent c) {
|
||||||
return sqrt(pow(this.y - c.y, 2) + pow(this.x - c.x, 2));
|
return sqrt(pow(this.y - c.y, 2) + pow(this.x - c.x, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class SpriteComponent extends PositionComponent {
|
abstract class SpriteComponent extends PositionComponent {
|
||||||
|
|
||||||
double width, height;
|
double width, height;
|
||||||
Image image;
|
Image image;
|
||||||
|
|
||||||
@ -46,22 +42,29 @@ abstract class SpriteComponent extends PositionComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render(Canvas canvas) {
|
render(Canvas canvas) {
|
||||||
canvas.translate(x, y);
|
|
||||||
canvas.rotate(angle); // TODO: rotate around center
|
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
final Rect outputRect = new Rect.fromLTWH(0.0, 0.0, width, height);
|
_prepareCanvas(canvas);
|
||||||
|
_drawImage(canvas);
|
||||||
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 _prepareCanvas(Canvas canvas) {
|
||||||
|
canvas.translate(x, y);
|
||||||
|
canvas.rotate(angle); // TODO: rotate around center
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {}
|
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:async';
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'dart:ui' as ui show TextStyle;
|
import 'dart:ui' as ui show TextStyle;
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
class Util {
|
class Util {
|
||||||
Future<Size> initialDimensions() async {
|
Future<Size> initialDimensions() async {
|
||||||
// https://github.com/flutter/flutter/issues/5259
|
// https://github.com/flutter/flutter/issues/5259
|
||||||
@ -29,13 +28,21 @@ class Util {
|
|||||||
new _CustomBinder();
|
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());
|
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);
|
paragraph.addText(text);
|
||||||
return paragraph.build()..layout(new ParagraphConstraints(width: maxWidth));
|
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