<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Happy Makadiya on Medium]]></title>
        <description><![CDATA[Stories by Happy Makadiya on Medium]]></description>
        <link>https://medium.com/@happy.m?source=rss-77d1ce0dce04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*r9Rwhi0YvsvuXevVISCv8Q.jpeg</url>
            <title>Stories by Happy Makadiya on Medium</title>
            <link>https://medium.com/@happy.m?source=rss-77d1ce0dce04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 02:14:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@happy.m/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Build Collision-Based Game Using Flame in Flutter]]></title>
            <link>https://medium.com/simform-engineering/build-collision-based-game-using-flame-in-flutter-ba1fc86702bd?source=rss-77d1ce0dce04------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba1fc86702bd</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-game]]></category>
            <category><![CDATA[collision]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[flame]]></category>
            <dc:creator><![CDATA[Happy Makadiya]]></dc:creator>
            <pubDate>Fri, 07 Oct 2022 06:37:27 GMT</pubDate>
            <atom:updated>2022-10-07T11:26:26.680Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q-a11kwaK6Id6pHzsOnA0w.png" /></figure><p>We can take advantage of Flame’s every functionality if our game has a strong basis. In this second part, we’ve covered the creation of the collision-based game.</p><h4>Check out part one</h4><p>Please have a look at part one if you have no prior knowledge of the Flame’s nature or functioning or if you wish to start with the fundamentals.</p><p><a href="https://medium.com/simform-engineering/basics-of-game-development-using-flame-bee1b8cf7320">Basics of Game Development using Flame</a></p><h3>Game Concept</h3><p>Here I’m going to explain my journey of creating Brick Breaker, a popular and fascinating collision-based game.</p><blockquote>At the bottom of the screen, there’s a single ball and, at the top, square blocks with corresponding numbers. The player can strike the squares using their fingers to pull back and release the ball at the desired angle to gradually reduce the number until all of them have been shot.</blockquote><p>Take a glance at the game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*XYR0OUxRjKVuPBZDgtTSPQ.gif" /></figure><p>This game has three fundamental components.</p><ol><li>The<strong> Ball</strong> can collide with and deflect away from other objects.</li><li><strong>Board</strong> has boundaries where the ball keeps bouncing and a draggable region where the ball is released at a particular angle.</li><li><strong>Bricks</strong> contain random numbers, which are reduced by one upon contact with the ball and destroyed at the zeroth value.</li></ol><p>The score is determined by how many more bricklayers are added until the first brick reaches the baseline of the board. The game is about crashing the best score; there is no requirement for winning.</p><p>Soooo, Let’s get started!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*ZHp-jVaWAI2vNtXjV637CQ.gif" /></figure><p>The main required things for this game app are <a href="https://pub.dev/packages/flame">Flame</a> — Flutter Game engine, <a href="https://pub.dev/packages/mobx">Mobx</a> — for State Management, and <a href="https://pub.dev/packages/get_it">get_it</a> — Service locator for store objects.</p><h4>States Of Game:</h4><p>The GameApp widget will observe the Game state and return the screen accordingly. So we have created enum for the GameState.</p><pre>enum GameState { launch, play, pause, gameOver }</pre><p>The primary game view is controlled by <strong>Play State</strong>, and if the game has been restarted, a new instance of the Game will be allocated to Game Board.</p><p>Launch, Pause, and GameOver are game states that provide basic pause and resume functionality with the navigate to home choice.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee9ceed28d91023e9d5c8ea3c5826184/href">https://medium.com/media/ee9ceed28d91023e9d5c8ea3c5826184/href</a></iframe><h3>Game Board Widget</h3><p>This screen is responsible for displaying the current and best score with the pause button feature. Apart from it, the Game will be loaded into the remaining part using <strong>Game Widget</strong> provided by Flame.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b553c7aacbfb66a45d1e41810234e1cb/href">https://medium.com/media/b553c7aacbfb66a45d1e41810234e1cb/href</a></iframe><p>From this point on, the game’s primary logic begins…</p><h3>Flame Game Class:</h3><p>Extend FlameGame with a new game class — BreakerGame. Mixins HasCollisionDetection and HasDraggables must be added if any game components have collision callbacks and draggable events respectively.</p><p>According to the Flame Life cycle, the onLoad() is called once during the component’s lifetime to run asynchronous initialization code for components. All sub-components will be loaded in the onLoad(). Components are added to the component tree using the add() method.</p><p>Priority of components allows you to control the order in which your components are rendered. For example, the ball should always be visible on top of all other components. And so, its priority has been set to 1.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f3a9f65a5e525851f9f8c1c445b7a6d/href">https://medium.com/media/5f3a9f65a5e525851f9f8c1c445b7a6d/href</a></iframe><h3>Game Components:</h3><p>As mentioned earlier, the Game will have Bricks, Board, and Ball. Let’s explore each one individually.</p><h4>1. Brick Component:</h4><p>It will be a rectangle component having collision callbacks. And this component will use the reference of the game, so hasGameRef&lt;BreakerGame&gt; mixin is added.</p><p><strong>Generate a random bricklayer:</strong></p><p>A list of BrickComponents with a brick size and a random count will be produced by getBrickLayer(). The brick size is calculated using — the number of bricks in a row and the size of the game widget.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c68c54c89ada46384ae98aac82c192ea/href">https://medium.com/media/c68c54c89ada46384ae98aac82c192ea/href</a></iframe><p>Implementation of BrickComponent Class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/415dac592d97ac4d91bcc097f05eb6e0/href">https://medium.com/media/415dac592d97ac4d91bcc097f05eb6e0/href</a></iframe><p>Let’s examine the steps performed on the brick component.</p><ol><li>We will put an initialization code for a brick within onLoad(). Since a parent generates the count value at random, we first use removeFromParent() to remove it from a parent if the count value is less than zero ().</li><li>The Brick has textComponent added because we will present the count value in text form.</li><li>To determine the collision of brick, RectangleHitbox() has been included. The HitBox is the standard building block to ascertain whether two objects have collided.</li><li>Every game tick causes onUpdate() to be invoked. The value textComponent will be set to count on each collision.</li><li>onCollision() callback gives PositionComponent as the parameter with whom the brick collides. So will check if the collided component is Ball then the count value will be reduced by one.</li></ol><p>Until the component stops colliding with other objects, onCollision() will keep getting called. Therefore, we always maintain the hasCollided boolean flag and call this function only once.</p><h4>2. Ball Component:</h4><p>The ball Component is in charge of rendering the aim liner and alters position when colliding with various hitboxes.</p><p>The BallState enum was developed to manage the state efficiently, giving users more control over whether to permit drag events, collisions, and ball movement.</p><pre>enum BallState { ideal, drag, release, completed }</pre><ol><li><strong>Render the aim liner and movement of the ball:</strong></li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57f83c5a9fe42f55783bb23d2ebe1a85/href">https://medium.com/media/57f83c5a9fe42f55783bb23d2ebe1a85/href</a></iframe><ol><li>On each game tick, render() will also be called. The path of the aim liner is drawn based on the aimAngle which will be determined by the drag methods of the board.</li><li>In update() : If the ball’s location is close to the board’s baseline, the ball state will change to BallState.complete.</li></ol><p>When the game state is changed to BallState.complete, the new bricklayer is placed on top of the old layer by repositioning each layer one step downward.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6cb2ea2f2ad72d3b0b916e59a7badcd/href">https://medium.com/media/c6cb2ea2f2ad72d3b0b916e59a7badcd/href</a></iframe><p>3. moveBall() will adjust the ball’s position in accordance with the directional variables (xSign &amp; ySign) and nextPosition variable,</p><p>xSign and ySign hold positive or negative signs; on that basis, the ball will move to the specific coordinate.</p><p><strong>2. Collision Callbacks with different hitboxes:</strong></p><p>Here, the ball may strike one of two possible Hitboxes: the Board or the Brick.</p><blockquote>The law of reflection states that…</blockquote><blockquote><strong>When a ray of light reflects off a surface, the angle of incidence is equal to the angle of reflection.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*KeqKDg1GS7Lqn9gW.jpg" /></figure><p>In our case, the same rule is in effect. Simply invert the sign of y — ySign — if the ball collides with the top/bottom side of the object. Invert the sign of x — xSign — if it collides with the left /right side of the object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/915627e0641f918f540adad3b3c87fb9/href">https://medium.com/media/915627e0641f918f540adad3b3c87fb9/href</a></iframe><p>The intersection point of two colliding objects and the component with which it collided are provided to us by onCollision() callbacks. A distinct approach is being used depending on the component type.</p><p>Note: In our case, we will get one or two intersection points while colliding.</p><ol><li><strong>Collision with the board:</strong> By using the intersection point and position-size of the board, we can identify where the ball hit the board. To have a better grasp, review the logic.</li><li><strong>Collision with brick:</strong> If the intersection point is one and if either x or y of two intersection points are the same, then we can say that ball might collide with the sides of the brick and change the directional Variable accordingly. Or else Ball would collide with the corner of the brick.</li></ol><h4>3. Board Component:</h4><p>The board component is responsible for providing an area in which the ball moves around. It has a drag gesture to determine in which direction the ball should be triggered. For that, we have added aDraggable mixin to override drag event callbacks.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03747b487041731bda6b10ad30b76cb1/href">https://medium.com/media/03747b487041731bda6b10ad30b76cb1/href</a></iframe><ol><li>Rectangle hitbox is added to the board to make it collidable.</li><li>Using onDragStart() will get _dragStartPosition, the starting point of the drag event.</li><li>On every, onDragUpdate(), we will get the event position. Using _dragStartPosition and info.eventPosition, the angle of the aim line is calculated. The Aim line is rendered into a ball component, which we’ll discuss in a while.</li><li>Using the onDragCancel event, the next position and direction (xSign &amp; ySign) of the ball has been calculated.</li></ol><p>We can determine slope via two known points: <strong><em>y — y1 = m (x — x1)</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/0*kpdJSsM_L3YzO59l.png" /></figure><p>Here 2 points are known: dragStartPosition and info.eventPosition; using that, we can determine the slope.</p><p>If you have basic knowledge of trigonometry, then</p><pre><strong>tanθ = slope <br>θ = tan-1(slope)</strong></pre><p>So using this <strong>θ, </strong>we can set the angle of the aim line.</p><p>Now we have the slope and center position of the ball, so using the above line formula, we can determine nextPosition of the ball.</p><p>And Booom! Done with all the required concepts to develop a fantastic collision-based game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Jn4Mv0FXeKTlzJ5jtCHSMw.gif" /></figure><p>You can play this game live from <a href="http://bricks-breaker.surge.sh/#/">here</a>.</p><h3>Conclusion:</h3><p>We’ve designed the Brick Breaker game to demonstrate the concepts of flame lifecycle methods, collision callbacks, and Drag events.</p><p>Also, we’ve seen that using enum will make it easier to maintain effective control over the game’s state and components.</p><h3>References:</h3><p><strong>Docs: </strong><a href="https://docs.flame-engine.org/1.3.0/">https://docs.flame-engine.org/1.3.0/</a></p><p><strong>Examples:</strong> <a href="https://examples.flame-engine.org/#/">https://examples.flame-engine.org/#/</a></p><p><strong>All in one:</strong> <a href="https://github.com/flame-engine/awesome-flame">https://github.com/flame-engine/awesome-flame</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba1fc86702bd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/simform-engineering/build-collision-based-game-using-flame-in-flutter-ba1fc86702bd">Build Collision-Based Game Using Flame in Flutter</a> was originally published in <a href="https://medium.com/simform-engineering">Simform Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basics of Game Development using Flame]]></title>
            <link>https://medium.com/simform-engineering/basics-of-game-development-using-flame-bee1b8cf7320?source=rss-77d1ce0dce04------2</link>
            <guid isPermaLink="false">https://medium.com/p/bee1b8cf7320</guid>
            <category><![CDATA[flutter-game]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flame]]></category>
            <dc:creator><![CDATA[Happy Makadiya]]></dc:creator>
            <pubDate>Mon, 29 Aug 2022 06:16:47 GMT</pubDate>
            <atom:updated>2022-10-07T07:02:57.507Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gucr7K4QYVMMjXC9WnsUYA.png" /></figure><p>Flutter is maturing in numerous aspects, from cross-platform application development to game development. Yes, You catch it correctly. You can use the Flutter Framework to develop everything from arcade games to casual games and many more.</p><blockquote>Assuming you have basic knowledge of Dart and Flutter, we’ve covered the basic required concepts to develop games in this blog.</blockquote><p>So, let’s dive in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*nDSYLnyd-gzH_M4T8d3OVA.gif" /></figure><p>There is one amazing software available that provides complete control over the creation of an elegant game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*A6Q9EplsYepUvSaFJha5Gw.png" /></figure><p>Flame is a 2D game engine made on top of Flutter that offers a wide variety of elements to build up an appropriate toolset for your game.</p><p>It provides effective game loop implementation with necessary functionalities like animations, sprite sheets, collision detection, and various components like CameraComponent, PositionComponent, TiledComponent, and many more. Also, Flame facilitates input functionalities like Tap, Drag, Gesture, and Keyboard.</p><p><a href="https://pub.dev/packages/flame">flame | Flutter package</a></p><p>Add Flame dependencies to the pubspec.yml file, and do not forget to do flutter pub get.</p><pre>dependencies:  <br>  flutter:    <br>    sdk: flutter  <br>  flame: ^1.3.0</pre><p>Start by adding the 2 lines given below into the main function. Next, we need to ensure Flutter is ready by calling WidgetsFlutterBinding.ensureInitialized(); and set the Game mode to FullScreen or based on your requirement.</p><pre>void main() {<br>  WidgetsFlutterBinding.<em>ensureInitialized</em>();<br>  Flame.<em>device</em>.fullScreen();<br>  runApp(const GameApp());<br>}</pre><h3>Components</h3><p>Components are the basic building blocks for a FlameGame. Any Entity or object within the game can be represented as a Component. It is quite similar to widgets in Flutter.</p><p><strong>Component Tree: </strong>Components must be added to the Component tree to become fully functional. In the Component Tree, every component has a single parent and can own any number of children.</p><p>In any framework, Everything from start to end and even updating state is managed by its lifecycle. In Flame also, every component has its own lifecycle to follow.</p><p><strong>Component LifeCycle: </strong>During its lifetime, each component goes through several stages that you can optionally implement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/0*mf85lVwroG7WwF6B.png" /></figure><p>The Usage of all these methods is based on their lifecycle behavior and user requirements.</p><ol><li><strong>onGameResize():</strong> Once in the beginning, when the component is added to the tree, and then invoked every time the screen is resized.</li><li><strong>onLoad():</strong> Used once during the component’s lifetime and to run asynchronous initialization code for components; you can think of it as an “asynchronous constructor.”</li><li><strong>onMount():</strong> When the component is done loading, and its parent is mounted correctly. If a component is removed from the tree and later added to another component, onMountwill be called again. For every onMountcall, there will be a corresponding call to onRemove. This method will run only if the parent is already mounted; else will wait in a queue.</li><li><strong>update():</strong> On Every Game tick. i.e., when you have to change the position of any component every second.</li><li><strong>render():</strong> After all the components are done updating. i.e., if you want to redraw/edit the canvas component after every update.</li></ol><p>Now let’s deep dive into the most crucial part of Flame, where every heart of logic is being written.</p><h3>Game Loop:</h3><p>Most games are built using either of these methods:</p><ol><li><strong>render():</strong> Takes canvas for drawing the current state of the game.</li><li><strong>update():</strong> Receive the delta time in seconds since the last update and allow it to move to the next state.</li></ol><h3>Flame Game:</h3><p>The FlameGame class implements a Component-based Game. The FlameGame is the root of the component tree. It can be extended to add your game logic, or you can keep that logic into child components.</p><p>Components are added to the tree using add(), addAll() or addToParent() methods. And can be removed using remove(), removeAll() or removeFromParent() methods.</p><pre>class MyGame extends FlameGame {<br>  @override<br>  Future&lt;void&gt; onLoad() async {<br>    //Load Components.<br>  }</pre><pre>  @override<br>  Color backgroundColor() =&gt; const Color(0x00000000);<br>}</pre><h3>Pause/Resuming game:</h3><p>A FlameGame can be paused and resumed in two ways:</p><ul><li>With the use of the pauseEngine and resumeEngine methods.</li><li>By changing the paused attribute.</li></ul><p>When pausing a FlameGame, the GameLoop is effectively paused, so that no updates or new renders happen until it is resumed.</p><h3>Game Widget:</h3><p>It is in charge of attaching a Game instance into the Flutter tree.</p><pre>void main() {<br>  final game = MyGame();<br>  runApp(GameWidget(game: game));<br>}</pre><p>Now let’s explore some of the essential components already provided by Flame.</p><h3>PositionComponent:</h3><p>It represents a positioned object on the screen and has a position, size, scale, angle, and anchor, transforming how the component is rendered. Children of the PositionComponent will be transformed in relation to the parent, which means that the position, angle, and scale will be relative to the parent’s state.</p><p><strong>Position:</strong> Represent the position of the component’s anchor in relation to its parent components in the form of Vector2.</p><p><strong>Size:</strong> The logical size of the component. It is used primarily for tap and collision detection. Thus, the size should equal the approximate bounding rectangle of the rendered picture. If you don’t specify the size of a PositionComponent, it will be equal to zero, and the component will not be able to respond to taps.</p><p><strong>Scale:</strong> The scale factor of the component. Scale can be distinct along the X and Y dimensions. A scale that’s less than 1 makes the component smaller and greater than 1 bigger. The scale can also be negative, which results in a mirror reflection along the corresponding axis.</p><p><strong>Anchor:</strong> This point is considered the logical “center” of the component or the point where Flame grabs the component. All transformations occur around this point.</p><p><strong>Angle:</strong> Rotation angle (in radians) of the component. The component will be rotated around its anchor point in the clockwise direction if the angle is positive or counterclockwise if the angle is negative.</p><p>See the below example for more detail.</p><p>Create a positional component by extending PositionalComponent. You can load other components as children into the load method.</p><pre>class CenterComponent extends PositionComponent {<br>  CenterComponent()<br>      : super(<br>          position: Vector2(100, 100),<br>          size: Vector2(50, 50),<br>          anchor: Anchor.<em>center</em>,<br>        );<br><br>  @override<br>  Future&lt;void&gt; onLoad() async {<br>    await add(<br>      PositionComponent(position: Vector2(0, -50)),<br>    );<br>  }<br>}</pre><p>Now add CenterComponent to the game.</p><pre>class MyGame extends FlameGame {<br>  @override<br>  Future&lt;void&gt; onLoad() async {<br>    add(CenterComponent());<br>  }<br>}</pre><h3>SpriteComponent:</h3><p>Now, what if you want to add some assets, say a player’s face, to your game?</p><p>Yes, Flame gives you complete control of the canvas to draw the objects you want, but in some cases, if you want to add your own images, then the SpriteComponent comes into the scene.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*oVi7SYVGiJ5H-p8JNZGyOg.png" /></figure><p>To add Sprite to your game, first, you need to follow the specific file structure of Flame to load files. The file structure Flame would expect the files to find would be:</p><blockquote>Note: Do not forget to add these sub-folders to pubspec.yaml file.</blockquote><pre>.<br>└── assets<br>    ├── audio<br>    │   └── backgroundMusic.mp3<br>    └── images<br>        ├── enemy.png<br>        └── player.png</pre><p>Consider the below example for loading the sprite components into the game.</p><pre>class MyGame extends FlameGame {<br>  @override<br>  Future&lt;void&gt; onLoad() async {<br>    final sprite = await Sprite.<em>load</em>(&#39;player.png&#39;);<br>    final player = SpriteComponent(<br>      sprite: sprite,<br>      size: Vector2.all(100),<br>    );<br>    add(player);<br>  }<br>}</pre><h3>CameraComponent</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/0*KY6Y4656sg5RQLCx.png" /></figure><p>CameraComponent is a component through which a World is observed. A camera is a regular component placed anywhere in the game tree. Most games will have at least one “main” camera for displaying the main game world.</p><p>A Camera component consists of 2 parts: Viewport and Viewfinder.</p><h4>Viewport</h4><p>Imagine that the world is covered with an infinite sheet of paper, but there is a “window.” That window is the viewport through which the world can be observed.</p><p>Viewport contains properties like the window’s size, shape, and position on the screen that describe the “window” itself.</p><p>The viewport’s size is equal to or smaller than the size of the game canvas. If it is smaller, then the viewport’s position specifies where exactly it is placed on the canvas.</p><p>Following viewports are available:</p><ol><li><strong>MaxViewport:</strong> Expands to the maximum size allowed by the game. It will be equal to the size of the game canvas.</li><li><strong>FixedSizeViewport : </strong>Rectangular viewport with fixed dimensions.</li><li><strong>FixedAspectRatioViewport: </strong>Rectangular viewport, which expands to fit into the game canvas but preserves its aspect ratio.</li><li><strong>CircularViewport</strong>: A fixed-size viewport in the shape of a circle.</li></ol><h4>ViewFinder:</h4><p>Viewfinder controls which part of the game world is currently visible through a viewport. The Viewfinder also controls the zoom level and the rotation angle of the view.</p><h4>Camera:</h4><p>The camera translates the game coordinate system from 1:1 to camera zoom level. This is useful when the world is not 1:1 with screen size.</p><p>There are 3 significant factors that determine the camera position:</p><ol><li><strong>Follow</strong>: The camera will follow this component, <em>ensuring </em>its position is fixed on the screen.</li><li><strong>Move: </strong>Move the camera to a specific world coordinate. This will be set to the top left of the camera.</li><li><strong>Shake: </strong>Add a shake effect on top of the current coordinate for a brief period.</li></ol><h3>Collision Detection</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*_UDfXVYrQSY9X4fo4BcP9A.gif" /></figure><p>Collision Detection is an essential feature in most games and responds accordingly when two components interact with each other. For example, hitting the ball on a surface to prevent moving forward. Also, in the Pac-man game, the player collides with the enemy or wall, picking up the coins.</p><p>So to detect collision on any component, there must be a precise bounding box around that component; Technically, it’s called HitBoxes.</p><p>The first step to enabling Collision Detection is adding HasCollisionDetection mixin to your game to keep track of the components that can collide.</p><pre>class MyGame extends FlameGame with HasCollisionDetection {}</pre><p>Hitbox can be built from three different types of shapes: Polygon, Rectangle, and Circle. Multiple hitboxes can be added to a component. Inbuilt Component is provided by Flame to add a hitbox to components that are PolygonHitbox, RectangleHitBox, and CircleHitbox.</p><pre>class MyComponent extends PositionComponent {<br>  Future&lt;void&gt; onLoad() async {<br>    add(RectangleHitbox());<br>  }<br>}</pre><p>The Flame doesn’t handle what should happen when more than one hitboxes collide, so it is up to the developer to implement the necessary kind of functionality.</p><p>To react to a collision, you should add the CollisionCallbacks mixin to your component.</p><pre>class MyCollidable extends PositionComponent with CollisionCallbacks {<br>  @override<br>  void onCollision(Set&lt;Vector2&gt; points, PositionComponent other) {<br>    if (other is MyComponent) {<br>      //...<br>    }<br>  }<br><br>  @override<br>  void onCollisionEnd(PositionComponent other) {<br>    if (other is MyComponent) {<br>      //...<br>    }<br>  }<br>}</pre><h3>Debug Mode:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*9PY23Q5OJGtk0LcB.png" /></figure><p>Flame is providing adebugMode variable. By Default value is false. To enable the debugging feature for a specific component, set its value to true for that component.</p><h3>Wrap up:</h3><p>Now we have a basic idea of developing a game that is entirely dependent on components and follows its lifecycle. And Game components render on canvas by their position and size and interact with each other.</p><p>Still, Flame is not limited to these topics only. It is limitless. You can explore more about it in by the below reference links.</p><p>Docs: <a href="https://docs.flame-engine.org/1.3.0/">https://docs.flame-engine.org/1.3.0/</a></p><p>Examples: <a href="https://examples.flame-engine.org/#/">https://examples.flame-engine.org/#/</a></p><p>Woohoo! Now You have enough knowledge to start creating your dream game using Flutter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*rsCsAvRfeBeSpWin_mRh9g.gif" /></figure><h3>What’s Next?</h3><p>In the next article, we will try to create a fantastic game with the help of Flame. So you can get a better understanding of developing real-time games.</p><p><a href="https://medium.com/simform-engineering/build-collision-based-game-using-flame-in-flutter-ba1fc86702bd">Build Collision-Based Game Using Flame in Flutter</a></p><p>Happy Coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bee1b8cf7320" width="1" height="1" alt=""><hr><p><a href="https://medium.com/simform-engineering/basics-of-game-development-using-flame-bee1b8cf7320">Basics of Game Development using Flame</a> was originally published in <a href="https://medium.com/simform-engineering">Simform Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>