mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
flutter formar
This commit is contained in:
@ -14,13 +14,15 @@ class MyGame extends BaseGame {
|
|||||||
_start() async {
|
_start() async {
|
||||||
Size size = await Flame.util.initialDimensions();
|
Size size = await Flame.util.initialDimensions();
|
||||||
|
|
||||||
final animation = await FlameAnimation.Animation.sequenced('chopper.png', 4, textureWidth: 48, textureHeight: 48, stepTime: 0.15);
|
final animation = await FlameAnimation.Animation.sequenced('chopper.png', 4,
|
||||||
|
textureWidth: 48, textureHeight: 48, stepTime: 0.15);
|
||||||
|
|
||||||
final animationComponent = AnimationComponent(100, 100, animation);
|
final animationComponent = AnimationComponent(100, 100, animation);
|
||||||
animationComponent.x = size.width / 2 - 100;
|
animationComponent.x = size.width / 2 - 100;
|
||||||
animationComponent.y = 100;
|
animationComponent.y = 100;
|
||||||
|
|
||||||
final reversedAnimationComponent = AnimationComponent(100, 100, animation.reversed());
|
final reversedAnimationComponent =
|
||||||
|
AnimationComponent(100, 100, animation.reversed());
|
||||||
reversedAnimationComponent.x = size.width / 2;
|
reversedAnimationComponent.x = size.width / 2;
|
||||||
reversedAnimationComponent.y = 100;
|
reversedAnimationComponent.y = 100;
|
||||||
|
|
||||||
@ -28,4 +30,3 @@ class MyGame extends BaseGame {
|
|||||||
add(reversedAnimationComponent);
|
add(reversedAnimationComponent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import 'package:flutter/material.dart';
|
|||||||
void main() => runApp(MyGame());
|
void main() => runApp(MyGame());
|
||||||
|
|
||||||
class MyGame extends BaseGame {
|
class MyGame extends BaseGame {
|
||||||
|
|
||||||
Svg svgInstance;
|
Svg svgInstance;
|
||||||
SvgComponent android;
|
SvgComponent android;
|
||||||
|
|
||||||
@ -31,5 +30,4 @@ class MyGame extends BaseGame {
|
|||||||
|
|
||||||
svgInstance.renderPosition(canvas, Position(100, 200), 300, 300);
|
svgInstance.renderPosition(canvas, Position(100, 200), 300, 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,8 @@ class Animation {
|
|||||||
///
|
///
|
||||||
/// All frames have the same [stepTime].
|
/// All frames have the same [stepTime].
|
||||||
|
|
||||||
Animation.spriteList(List<Sprite> sprites, {double stepTime, this.loop = true}) {
|
Animation.spriteList(List<Sprite> sprites,
|
||||||
|
{double stepTime, this.loop = true}) {
|
||||||
frames = sprites.map((s) => Frame(s, stepTime)).toList();
|
frames = sprites.map((s) => Frame(s, stepTime)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,12 +22,12 @@ abstract class Box2DComponent extends Component {
|
|||||||
|
|
||||||
Box2DComponent({
|
Box2DComponent({
|
||||||
this.dimensions,
|
this.dimensions,
|
||||||
int worldPoolSize= DEFAULT_WORLD_POOL_SIZE,
|
int worldPoolSize = DEFAULT_WORLD_POOL_SIZE,
|
||||||
int worldPoolContainerSize= DEFAULT_WORLD_POOL_CONTAINER_SIZE,
|
int worldPoolContainerSize = DEFAULT_WORLD_POOL_CONTAINER_SIZE,
|
||||||
double gravity= DEFAULT_GRAVITY,
|
double gravity = DEFAULT_GRAVITY,
|
||||||
this.velocityIterations= DEFAULT_VELOCITY_ITERATIONS,
|
this.velocityIterations = DEFAULT_VELOCITY_ITERATIONS,
|
||||||
this.positionIterations= DEFAULT_POSITION_ITERATIONS,
|
this.positionIterations = DEFAULT_POSITION_ITERATIONS,
|
||||||
double scale= DEFAULT_SCALE,
|
double scale = DEFAULT_SCALE,
|
||||||
}) {
|
}) {
|
||||||
dimensions ??= window.physicalSize;
|
dimensions ??= window.physicalSize;
|
||||||
final pool = DefaultWorldPool(worldPoolSize, worldPoolContainerSize);
|
final pool = DefaultWorldPool(worldPoolSize, worldPoolContainerSize);
|
||||||
|
|||||||
@ -16,10 +16,10 @@ class TextBoxConfig {
|
|||||||
final double dismissDelay;
|
final double dismissDelay;
|
||||||
|
|
||||||
const TextBoxConfig({
|
const TextBoxConfig({
|
||||||
this.maxWidth= 200.0,
|
this.maxWidth = 200.0,
|
||||||
this.margin= 8.0,
|
this.margin = 8.0,
|
||||||
this.timePerChar= 0.0,
|
this.timePerChar = 0.0,
|
||||||
this.dismissDelay= 0.0,
|
this.dismissDelay = 0.0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +157,8 @@ class TextBoxComponent extends PositionComponent with Resizable {
|
|||||||
.paint(c, Offset(_boxConfig.margin, dy));
|
.paint(c, Offset(_boxConfig.margin, dy));
|
||||||
dy += _lineHeight;
|
dy += _lineHeight;
|
||||||
}
|
}
|
||||||
final int max = math.min(currentChar - charCount, _lines[_currentLine].length);
|
final int max =
|
||||||
|
math.min(currentChar - charCount, _lines[_currentLine].length);
|
||||||
_config
|
_config
|
||||||
.toTextPainter(_lines[_currentLine].substring(0, max))
|
.toTextPainter(_lines[_currentLine].substring(0, max))
|
||||||
.paint(c, Offset(_boxConfig.margin, dy));
|
.paint(c, Offset(_boxConfig.margin, dy));
|
||||||
|
|||||||
@ -29,7 +29,8 @@ class Svg {
|
|||||||
/// Renders the svg on the [canvas] on the given [position] using the dimmensions provided on [width] and [height]
|
/// Renders the svg on the [canvas] on the given [position] using the dimmensions provided on [width] and [height]
|
||||||
///
|
///
|
||||||
/// If not loaded, does nothing
|
/// If not loaded, does nothing
|
||||||
void renderPosition(Canvas canvas, Position position, double width, double height) {
|
void renderPosition(
|
||||||
|
Canvas canvas, Position position, double width, double height) {
|
||||||
if (!loaded()) {
|
if (!loaded()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,11 +53,11 @@ class TextConfig {
|
|||||||
///
|
///
|
||||||
/// Every parameter can be specified.
|
/// Every parameter can be specified.
|
||||||
const TextConfig({
|
const TextConfig({
|
||||||
this.fontSize= 24.0,
|
this.fontSize = 24.0,
|
||||||
this.color= const Color(0xFF000000),
|
this.color = const Color(0xFF000000),
|
||||||
this.fontFamily= 'Arial',
|
this.fontFamily = 'Arial',
|
||||||
this.textAlign= TextAlign.left,
|
this.textAlign = TextAlign.left,
|
||||||
this.textDirection= TextDirection.ltr,
|
this.textDirection = TextDirection.ltr,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Renders a given [text] in a given position [p] using the provided [canvas] and [anchor].
|
/// Renders a given [text] in a given position [p] using the provided [canvas] and [anchor].
|
||||||
@ -70,7 +70,7 @@ class TextConfig {
|
|||||||
/// const TextConfig config = TextConfig(fontSize: 48.0, fontFamily: 'Awesome Font', anchor: Anchor.rightBottom);
|
/// const TextConfig config = TextConfig(fontSize: 48.0, fontFamily: 'Awesome Font', anchor: Anchor.rightBottom);
|
||||||
/// config.render(c, Offset(size.width - 10, size.height - 10);
|
/// config.render(c, Offset(size.width - 10, size.height - 10);
|
||||||
void render(Canvas canvas, String text, Position p,
|
void render(Canvas canvas, String text, Position p,
|
||||||
{Anchor anchor= Anchor.topLeft}) {
|
{Anchor anchor = Anchor.topLeft}) {
|
||||||
final material.TextPainter tp = toTextPainter(text);
|
final material.TextPainter tp = toTextPainter(text);
|
||||||
final Position translatedPosition =
|
final Position translatedPosition =
|
||||||
anchor.translate(p, Position.fromSize(tp.size));
|
anchor.translate(p, Position.fromSize(tp.size));
|
||||||
|
|||||||
Reference in New Issue
Block a user