Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

main

./lib/main.dart

import 'package:flame/game.dart';
import 'package:flutter/material.dart';

void main() {
  MyGame game = MyGame();

  runApp(MaterialApp(
    home: Scaffold(
      body: Stack(
        children: <Widget>[
          GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTapDown: (TapDownDetails d) {
              // place your tap down handler code here
            },
            onTapUp: (TapUpDetails d) {
              // place your tap up handler code here
            },
            child: game.widget,
          ),
          Text('This is the HUD UI'),
        ],
      ),
    ),
  ));
}

class MyGame extends Game {
  Size screenSize;

  void render(Canvas canvas) {
    if (screenSize == null) return;

    canvas.drawRect(
      Rect.fromLTWH(
        0,
        0,
        screenSize.width,
        screenSize.height,
      ),
      Paint()..color = Color(0xfff8c291),
    );
  }

  void update(double t) {}

  void resize(Size size) {
    screenSize = size;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.