0

I want to make series of dots in my app using flame. So far I know about Custom paint and all but what I am using here is SpriteComponent and want to use it only to make draw dots

This is what I tried:

*****main*******

var game;
const ComponentSize = 40.0;

void main() async {
  await Flame.util.fullScreen();
  await Flame.images.loadAll([
    'dotbg1.jpg',
    'dot-line1.png',
    'dot-ball.png',
  ]);
  runApp(MaterialApp(
      home: Scaffold(
          body: Container(
    decoration: new BoxDecoration(
      image: new DecorationImage(
        image: new AssetImage("assets/dotbg1.jpg"),
        fit: BoxFit.cover,
      ),
    ),
    child: (MyGame().widget),
  ))));
}

class MyGame extends BaseGame {
  @override
  void render(Canvas canvas) {}

  @override
  void update(double t) {}
}

*****dot.dart********

class Component extends SpriteComponent {
  Size dimensions;
  int position;
  int yposition;

  Component(this.dimensions,this.position, this.yposition) : super.square(ComponentSize, 'dot-ball.png');
}

When I am running, I am getting a blank screen and my console output is below: enter image description here

Expectation: The image below is what I need to draw enter image description here

What am I doing wrong here?

Luan Nico
  • 5,376
  • 2
  • 30
  • 60
Prianca
  • 1,035
  • 5
  • 16
  • 30

2 Answers2

0

You cannot directly use a CustomPainter as a widget. A custom painter is intended to paint inside a CustomPaint widget. So your code should be something like this

CustomPaint(
  painter: ShapesPainter(),
)
Ajil O.
  • 6,562
  • 5
  • 40
  • 72
0

flame image assets need to be in folder assets/images. Also assets/images/ must be in your pubspec,yaml.

Tidder
  • 1,126
  • 1
  • 7
  • 15