sprite_widget.dart 1.48 KB
Newer Older
1
part of flutter_sprites;
2 3

/// A widget that uses a [SpriteBox] to render a sprite node tree to the screen.
4
class SpriteWidget extends OneChildRenderObjectWidget {
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

  /// The rootNode of the sprite node tree.
  ///
  ///     var node = mySpriteWidget.rootNode;
  final NodeWithSize rootNode;

  /// The transform mode used to fit the sprite node tree to the size of the widget.
  final SpriteBoxTransformMode transformMode;

  /// Creates a new sprite widget with [rootNode] as its content.
  ///
  /// The widget will setup the coordinate space for the sprite node tree using the size of the [rootNode] in
  /// combination with the supplied [transformMode]. By default the letterbox transform mode is used. See
  /// [SpriteBoxTransformMode] for more details on the different modes.
  ///
  /// The most common way to setup the sprite node graph is to subclass [NodeWithSize] and pass it to the sprite widget.
  /// In the custom subclass it's possible to build the node graph, do animations and handle user events.
  ///
  ///     var mySpriteTree = new MyCustomNodeWithSize();
  ///     var mySpriteWidget = new SpriteWidget(mySpriteTree, SpriteBoxTransformMode.fixedHeight);
  SpriteWidget(this.rootNode, [this.transformMode = SpriteBoxTransformMode.letterbox]);

27
  SpriteBox createRenderObject() => new SpriteBox(rootNode, transformMode);
28

29
  void updateRenderObject(SpriteBox renderObject, SpriteWidget oldWidget) {
30 31
    renderObject.rootNode = rootNode;
    renderObject.transformMode = transformMode;
32
  }
33
}