mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-30 08:27:36 +08:00
Unify examples structure (#1118)
* Animations, CameraAndViewport, CollisionDetection and Components unified * Added descriptions to effects * Rename input games * Unify input stories * Add info to parallax section * Added descriptions to the rendering examples * Add descriptions to the sprites directory * Fix utils and rendering section * Add descriptions to the widgets section * Delete directory that rebase brought back * Unify game names * Added some styleguide docs for examples * Fix analyze issues * All files should have _example as suffix * Made the FollowComponentExample a bit easier to understand * Change priority of ember
This commit is contained in:
39
examples/lib/stories/rendering/nine_tile_box_example.dart
Normal file
39
examples/lib/stories/rendering/nine_tile_box_example.dart
Normal file
@ -0,0 +1,39 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/input.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class NineTileBoxExample extends FlameGame with TapDetector, DoubleTapDetector {
|
||||
static const String description = '''
|
||||
If you want to create a background for something that can stretch you can
|
||||
use the `NineTileBox` which is showcased here.\n\n
|
||||
Tap to make the box bigger and double tap to make it smaller.
|
||||
''';
|
||||
|
||||
late NineTileBox nineTileBox;
|
||||
final Vector2 boxSize = Vector2.all(300);
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
final sprite = Sprite(await images.load('nine-box.png'));
|
||||
nineTileBox = NineTileBox(sprite, tileSize: 8, destTileSize: 24);
|
||||
}
|
||||
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
super.render(canvas);
|
||||
final position = (size - boxSize) / 2;
|
||||
nineTileBox.draw(canvas, position, boxSize);
|
||||
}
|
||||
|
||||
@override
|
||||
void onTap() {
|
||||
boxSize.scale(1.2);
|
||||
}
|
||||
|
||||
@override
|
||||
void onDoubleTap() {
|
||||
boxSize.scale(0.8);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user