Draw a rectangle in Flame with Flutter

Previously, we saw how to draw a circle in Flame using the Canvas, continuing with the basic shapes, we are going to draw a rectangle or square in Flame.

Recap a bit; Flame is a 2D game engine that runs on top of Flutter; very easy to use and with which we can start in the world of 2D game development; with a Flutter project, we can have the same game for different platforms like Windows, Linux, MacOS and of course, mobile devices.

With Flame, we can create cross-platform 2D games for iOS and Android.

Flame offers many ready-to-use features like sprites, collision handling, input events, etc. It also offers support for audio integration among many other things.

 

To draw a rectangle we can use exactly the same code presented in drawing a circle in Flame but, changing the function of the canvas with:

canvas.drawRect(Rect.fromCircle(center: const Offset(0, 0), radius: 20), BasicPalette.red.paint());

Remember that we started from the development of drawing a circle in Flame.

- Andrés Cruz

En español
Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz In Udemy

I agree to receive announcements of interest about this Blog.