ゲーム内に四角形を描写するにはRectangleComponentを使います。
目次
四角形を描写する
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flutter/material.dart';
void main() {
  final game = SampleGame();
  runApp(
      GameWidget(game: game)
  );
}
class SampleGame extends FlameGame {
  @override
  Future<void> onLoad() async {
    await add(
      RectangleComponent(
        size: Vector2.all(100),
      ),
    );
  }
}
これでゲーム内に白い四角形が表示されました。
四角形の色や位置を変更する
RectangleComponentには位置や色などを設定するプロパティを持っているので、それらを設定することで四角形をカスタマイズできます。
| プロパティ | 概要 | 
|---|---|
| position | 位置座標 | 
| size | 大きさ | 
| angle | 角度 | 
| anchor | 描画の基準点(デフォルトは左上) | 
| paint | 色などの設定 | 
RectangleComponent(
    size: Vector2.all(100), // 四角形のサイズ
    position: Vector2(size.x * 0.5, size.y * 0.5), // 画面の中央に
    anchor: Anchor.center, // 基準点を中心に(デフォルトは左上が基準点)
    angle: pi/4, // 45度回転
    paint: Paint()
      ..color = Colors.yellow, // 色を黄色に
),


Comment