mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-11 18:11:12 +08:00
Adding a rotate method to Position and a drawWhere method to utils
This commit is contained in:
@@ -22,4 +22,12 @@ class Position {
|
|||||||
double length() {
|
double length() {
|
||||||
return math.sqrt(math.pow(this.x, 2) + math.pow(this.y, 2));
|
return math.sqrt(math.pow(this.x, 2) + math.pow(this.y, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Position rotate(double angle) {
|
||||||
|
double nx = math.cos(angle) * this.x - math.sin(angle) * this.y;
|
||||||
|
double ny = math.sin(angle) * this.x + math.cos(angle) * this.y;
|
||||||
|
this.x = nx;
|
||||||
|
this.y = ny;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import 'package:flutter/gestures.dart';
|
|||||||
import 'package:flutter/material.dart' as material;
|
import 'package:flutter/material.dart' as material;
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
import 'position.dart';
|
||||||
|
|
||||||
class Util {
|
class Util {
|
||||||
void fullScreen() {
|
void fullScreen() {
|
||||||
SystemChrome.setEnabledSystemUIOverlays([]);
|
SystemChrome.setEnabledSystemUIOverlays([]);
|
||||||
@@ -46,4 +48,10 @@ class Util {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawWhere(Canvas c, Position p, void Function(Canvas) fn) {
|
||||||
|
c.translate(p.x, p.y);
|
||||||
|
fn(c);
|
||||||
|
c.translate(-p.x, -p.y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user