mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
adding anchor to sprite and animation widget
This commit is contained in:
@ -8,6 +8,32 @@ import 'package:flame/widgets/nine_tile_box.dart';
|
||||
import 'package:flame/widgets/sprite_button.dart';
|
||||
import 'package:flame/widgets/sprite_widget.dart';
|
||||
import 'package:flame/widgets/animation_widget.dart';
|
||||
import 'package:flame/anchor.dart';
|
||||
|
||||
Anchor parseAnchor(String name) {
|
||||
switch (name) {
|
||||
case 'Anchor.topLeft':
|
||||
return Anchor.topLeft;
|
||||
case 'Anchor.topCenter':
|
||||
return Anchor.topCenter;
|
||||
case 'Anchor.topRight':
|
||||
return Anchor.topRight;
|
||||
case 'Anchor.centerLeft':
|
||||
return Anchor.centerLeft;
|
||||
case 'Anchor.center':
|
||||
return Anchor.center;
|
||||
case 'Anchor.centerRight':
|
||||
return Anchor.centerRight;
|
||||
case 'Anchor.bottomLeft':
|
||||
return Anchor.bottomLeft;
|
||||
case 'Anchor.bottomCenter':
|
||||
return Anchor.bottomCenter;
|
||||
case 'Anchor.bottomRight':
|
||||
return Anchor.bottomRight;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@ -63,16 +89,27 @@ void main() async {
|
||||
),
|
||||
);
|
||||
|
||||
final anchorOptions = [
|
||||
'Anchor.topLeft',
|
||||
'Anchor.topCenter',
|
||||
'Anchor.topRight',
|
||||
'Anchor.centerLeft',
|
||||
'Anchor.center',
|
||||
'Anchor.centerRight',
|
||||
'Anchor.bottomLeft',
|
||||
'Anchor.bottomCenter',
|
||||
'Anchor.bottomRight',
|
||||
];
|
||||
final shieldSprite = await Sprite.loadSprite('shield.png');
|
||||
dashbook.storiesOf('SpriteWidget').decorator(CenterDecorator()).add(
|
||||
'default',
|
||||
(ctx) => Container(
|
||||
width: ctx.numberProperty('container width', 400),
|
||||
height: ctx.numberProperty('container height', 200),
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: SpriteWidget(
|
||||
sprite: shieldSprite,
|
||||
center: ctx.boolProperty('center', true),
|
||||
anchor: parseAnchor(
|
||||
ctx.listProperty('anchor', 'Anchor.center', anchorOptions)),
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -85,22 +122,18 @@ void main() async {
|
||||
columns: 4,
|
||||
rows: 1,
|
||||
);
|
||||
final _animation = _animationSpriteSheet.createAnimation(
|
||||
0,
|
||||
stepTime: 0.2,
|
||||
to: 3,
|
||||
loop: true,
|
||||
);
|
||||
final _animation = _animationSpriteSheet.createAnimation(0,
|
||||
stepTime: 0.2, to: 3, loop: true);
|
||||
dashbook.storiesOf('AnimationWidget').decorator(CenterDecorator()).add(
|
||||
'default',
|
||||
(ctx) => Container(
|
||||
width: ctx.numberProperty('container width', 400),
|
||||
height: ctx.numberProperty('container height', 200),
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: AnimationWidget(
|
||||
animation: _animation,
|
||||
play: ctx.boolProperty('playing', true),
|
||||
center: ctx.boolProperty('center', true),
|
||||
anchor: parseAnchor(
|
||||
ctx.listProperty('anchor', 'Anchor.center', anchorOptions)),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user