Reader small image

You're reading from  Building Games with Flutter

Product typeBook
Published inJun 2022
PublisherPackt
ISBN-139781801816984
Edition1st Edition
Concepts
Right arrow
Author (1)
Paul Teale
Paul Teale
author image
Paul Teale

Paul Teale was born and raised in Leeds, West Yorkshire before moving to London to pursue a career in software engineering. He has been a software engineer for 25+ years covering backend, web, and mobile, where he has spent the last 12 years as a mobile developer covering Android and more recently Flutter. He has worked on many large projects during his career for companies like Discovery, Sky, Shazam, Visa, NBC, and Channel 5. He is a massive sci-fi fan and loves watching all the latest movies. He is happily married for the last 15 years to Mariel where they live together in West London with their son Alfie and their 2 cats.
Read more about Paul Teale

Right arrow

Chapter 1

  1. The minimum constant frame rate Flutter draws at is 60 frames per second.
  2. The graphics engine used by Flutter is Skia.
  3. Android, iPhone, Mac, Linux, Windows, and the Web can be supported with Flutter.
  4. Skia is an open-source graphics engine that provides graphics APIs for drawing shapes, text, and images.
  5. Dart supports both just-in-time and ahead-of-time compilation. Just-in-time compilation provides great features like stateful hot reload while debugging, and ahead-of-time compilation provides high performances when the game is released.
  6. Stateful hot reload allows you to make a change to your code, reload it, and instantly see the change (it's like painting with code!).
  7. Dart uses fast garbage collection for short lived objects, allowing Dart to rebuild the widget tree at 60 frames per second for smooth animation.

Chapter 2

  1. deltaTime is the time that has elapsed between frames. This is used to ensure that the frame rate stays constant across devices with different processing powers.
  2. The Flame Component System allows us to build a flexible architecture for our game which is essential as our game grows.
  3. HitboxRectangle is used for detecting shapes that are squares or rectangles.

Chapter 3

  1. A synopsis gives a high-level summary of the game's goals used to entice players to play the game.
  2. George's health will reduce by 25% when an enemy attacks him.
  3. George's score increases by 20 points for every gold coin collected.
  4. Water is used to define boundaries that George or the enemies cannot cross.

Chapter 4

  1. A sprite is a graphic or image asset that can be static or animated.
  2. The functions createAnimationByColumn or createAnimationByRow return a sprite animation list.
  3. SpriteAnimationComponent reduces the amount of extra code we need as animation is built into the component by design.
  4. A range is specified using the to and from parameters to represent the start and end animation frames.
  5. A base class allows us to set up common behaviors that the sprites will share.

Chapter 5

  1. A HUD is a Heads-Up Display. It represents a user interface that we want to draw on top of our game, showing things like score and health.
  2. To detect touches, we use the Tappable mixin.
  3. A TextComponent is used to draw text on the screen.
  4. A joystick has an inner control which needs to be dragged to the outer control to register a value for the joystick's direction.

Chapter 6

  1. We use the flame_audio library to add audio to our games.
  2. Loading audio into a memory cache ahead of time improves your game's performance, as we are usually going to play the same sound effects many times in the game.
  3. We need to clear the buffer to prevent holding onto the resource and causing memory leaks, which may crash our game.
  4. We need to listen for pause events when the game is backgrounded and resume events when the game is brought back into focus.
  5. We need to store a reference to the AudioPlayer that is returned for longer sound effects, so we can control the sound if the game is paused or resumed.
  6. We use the volume parameter passed to the play function of FlameAudio.

Chapter 7

  1. The Tiled application allows us to create tile maps that are much larger than the physical screen of our game, by using tile sets made up of small tiles to represent things like grass or water.
  2. Tile maps reuse each tile, meaning that they take up much less memory than storing a larger image.
  3. Tile map data is stored in a 2D array to represent the width and height of the map.
  4. We can use tile layers for representing the tiles and object layers for objects we want to draw on top of the map.
  5. To adjust the map as a sprite moves around, we use a camera and set up the followComponent function with the component that we want to focus on while it moves.
  6. We can add collidable objects as an object layer in our tile map and then create components from these by reading the object with the tile map getObjectGroupFromLayer function.
  7. A collidable object can be active, passive, or inactive. We use these to reduce the amount of collision checks between collidable...

Chapter 8

  1. Web browsers require audio permissions to be enabled when first loaded to prevent web sites irritating the user with annoying noises.
  2. Our game is set up with an initial size based on the dimensions of the screen. If this changes, everything now needs to be recalculated, otherwise things like the joysticks won't be positioned correctly.
  3. The default TiledComponent doesn't need a position and size. but to fix issues when resizing, we need to be able to recalculate these values. So, we wrap the component in a PositionComponent to give us the position and size values.
  4. We can use canvaskit for prioritizing performance or html for prioritizing download size.
  5. We use the KeyboardHandler mixin to listen for key events.

Chapter 9

  1. lifespan and count are common properties to set when using particles. They represent how long the particle should be shown for and how many should be shown, respectively.
  2. Particles created a lot of objects very quickly and can use up a lot of memory, so we need to free up the memory once the particle is no longer in use.
  3. MovingParticle, CircleParticle, and ComputedParticle are examples of particles that Flame supports.
  4. Flame supports the PreRenderedLayer for static images and the DynamicLayer for animated images.
  5. We need to delegate the rendering of the super class to the layer class so that the layer processor can do its work of generating the shadow image.

Chapter 10

  1. We can use the distanceTo function to measure the distance between two position vectors.
  2. The algorithm we used in Gold Rush for pathfinding is known as A* (A Star).
  3. We can multiply or divide the x or y position by the tile size to convert between world and grid coordinates.
  4. Turning withDiagonal to true provides more natural movement to our characters, otherwise the characters will move at right angles which look robotic!
  5. Every time we change direction, we must match the correct animation, or we will get issues like the sprite appearing to walk backwards.

Chapter 11

  1. To persist simple data, we use the shared_preferences library.
  2. To monetize a game, we can use adverts, in-app purchases, or a fixed cost purchase.
  3. The Navigator class is used to change screens in Flutter.
  4. With in-app purchases, you can resell the same digital asset to many people for a repeatable revenue stream.

Why subscribe?

  • Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
  • Improve your learning with Skill Plans built especially for you
  • Get a free eBook or video every month
  • Fully searchable for easy access to vital information
  • Copy and paste, print, and bookmark content

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Building Games with Flutter
Published in: Jun 2022Publisher: PacktISBN-13: 9781801816984
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Paul Teale

Paul Teale was born and raised in Leeds, West Yorkshire before moving to London to pursue a career in software engineering. He has been a software engineer for 25+ years covering backend, web, and mobile, where he has spent the last 12 years as a mobile developer covering Android and more recently Flutter. He has worked on many large projects during his career for companies like Discovery, Sky, Shazam, Visa, NBC, and Channel 5. He is a massive sci-fi fan and loves watching all the latest movies. He is happily married for the last 15 years to Mariel where they live together in West London with their son Alfie and their 2 cats.
Read more about Paul Teale