Author's avatar

Funny guy

Published on September 29, 2023

Unity alternative

Hero image

Intro

Unity announced a change in their Runtime Fee pricing policy on 12th of September that lately caused a lot of irritation. After a lot of buzz in social media they updated the policy on 22nd of September which is a lot more developer friendly (f.e. it is now optional to display a Splash Screen at the startup of the game, etc.) Read all updates here.

All in all this might trigger some developers to take a closer look at alternative engines to develop their games.

And for this we have a great suggestion: Flame with Flutter.

Flame as alternative

Flame is a modular game engine that provides a complete set of out-of-the-way solutions for games - and it is a great alternative to Unity (especially for mobile games, but more on this later).

Flame is based on Flutter and therefore simplifies the development for mobile platforms significantly: Flutter enables the development of mobile apps from only a single codebase. And apps written in Flutter perform at native speed - an important factor for a game engine to support mobile games.

Games developed with Flame are written in Dart. Dart is also called "Java lite" - which is quite accurate.

Check out a simple Dart example:

import 'dart:math' show Random;

void main() async {
  print('Compute π using the Monte Carlo method.');
  await for (final estimate in computePi().take(100)) {
    print('π ≅ $estimate');
  }
}

/// Generates a stream of increasingly accurate estimates of π.
Stream<double> computePi({int batch = 100000}) async* {
  var total = 0; // Inferred to be of type int
  var count = 0;
  while (true) {
    final points = generateRandom().take(batch);
    final inside = points.where((p) => p.isInsideUnitCircle);

    total += batch;
    count += inside.length;
    final ratio = count / total;

    // Area of a circle is A = π⋅r², therefore π = A/r².
    // So, when given random points with x ∈ <0,1>,
    // y ∈ <0,1>, the ratio of those inside a unit circle
    // should approach π / 4. Therefore, the value of π
    // should be:
    yield ratio * 4;
  }
}

Iterable<Point> generateRandom([int? seed]) sync* {
  final random = Random(seed);
  while (true) {
    yield Point(random.nextDouble(), random.nextDouble());
  }
}

class Point {
  final double x;
  final double y;

  const Point(this.x, this.y);

  bool get isInsideUnitCircle => x * x + y * y <= 1;
}

Whereas the details of this example are out of the scope of this blog-post you might already see some parallels to the Java programming language.

Although Dart is type-safe, you can declare most variables without explicitly specifying their type using var. Thanks to type inference, these variables' types are determined by their initial values.

A simple Flame game implementation that adds two components, one in onLoad and one directly in the constructor is implemented in this simple example:

import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flutter/widgets.dart';

/// A component that renders the crate sprite, with a 16 x 16 size.
class MyCrate extends SpriteComponent {
  MyCrate() : super(size: Vector2.all(16));

  @override
  Future<void> onLoad() async {
    sprite = await Sprite.load('crate.png');
  }
}

class MyWorld extends World {
  @override
  Future<void> onLoad() async {
    await add(MyCrate());
  }
}

void main() {
  final myGame = FlameGame(world: MyWorld());
  runApp(
    GameWidget(game: myGame),
  );
}

When it comes to mobile game development, Unity has been a go-to platform for many developers due to its versatility and robust features. However, in recent years, a new player has emerged on the scene that is challenging Unity's dominance in the mobile game development arena. Enter Flutter Flame, a combination of the Flutter framework and the Flame game engine, which offers a compelling alternative for creating mobile games. In this blog post, we'll explore why Flutter Flame is a valid Unity alternative for mobile game development.

Cross-Platform Development: One of the biggest advantages of Flutter Flame is its cross-platform capabilities. Flutter itself is known for its ability to create apps for both iOS and Android from a single codebase, and when combined with Flame, it becomes a powerful tool for game developers. Unity does offer cross-platform support, but Flutter Flame's approach is seamless, making it easier to reach a wider audience with minimal additional effort.

Open Source and Community-Driven: Flutter Flame is open-source, which means developers have access to the source code and can customize it to suit their specific needs. This openness fosters a strong and active community, resulting in regular updates, bug fixes, and the creation of helpful plugins and extensions. Unity, while robust, is not as open, and the community around Flutter Flame is growing rapidly.

Performance: Mobile game performance is crucial, and Flutter Flame doesn't disappoint. The combination of Flutter's native-like performance and Flame's optimized game engine ensures that your games run smoothly on a wide range of devices. Unity also offers good performance, but Flutter Flame's lightweight nature can be advantageous, especially for less powerful devices.

Learning Curve: For newcomers to game development, Unity's learning curve can be steep. Flutter Flame, on the other hand, leverages the simplicity of the Dart programming language and the intuitive Flutter framework, making it more accessible to developers with different levels of experience. The development process is more straightforward, which can save time and resources.

Small App Size: Mobile gamers often prioritize app size. Flutter Flame produces smaller app binaries compared to Unity, which can be a significant advantage, particularly in regions where data and storage limitations are a concern.

Rapid Prototyping: Flutter Flame's hot-reloading feature, inherited from Flutter, allows developers to see changes in real-time, making it ideal for rapid prototyping and iterative development. Unity has a similar feature, but Flutter Flame's implementation is known for its speed and responsiveness.

2D Game Focus: While Unity is a versatile engine for both 2D and 3D games, Flutter Flame specializes in 2D game development. If your project primarily involves 2D graphics, Flutter Flame may offer a more streamlined and efficient development process.

Conclusion

In conclusion, while Unity remains a powerhouse in the game development industry, Flutter Flame presents a strong alternative for mobile game developers, especially those looking for a more accessible, cross-platform, and lightweight solution. The decision between Unity and Flutter Flame ultimately depends on your project's specific requirements and your familiarity with the tools. As Flutter Flame continues to evolve and gain traction, it's certainly worth considering for your next mobile game development venture.

Try to survive

Creepy alien crawlies are entering the city. Get your weapons of choice ready and free the city!

YouTube Thumbnail

Join our #public-beta Discord-Server 👋

Connect with fellow gamers, share feedback directly to our dev team, and get exclusive sneak peeks into the development process.
Be part of the gaming revolution! 🕹️ #IndieGameBeta 📱
It's worth it, we promise 😊 #adsfree, #nobullsh!t
Feel free to join now!