Home > front end >  XmlParseException error when using Flutter Flame engine
XmlParseException error when using Flutter Flame engine

Time:06-02

I am creating a game in Flutter using the Flame game engine I created a level with the help of tiled. When I run the app in the emulator I am getting the following errors.

[log] Error while loading Game widget
[log] XmlParserException (XmlParserException: "<" expected at 1:1)
[log] #0      new XmlDocument.parse
package:xml/…/nodes/document.dart:35
The following XmlParserException was thrown building FutureBuilder<void>(dirty, state: _FutureBuilderState<void>#1f3ee):
"<" expected at 1:1

Here is the code

Main Class:

import 'package:flutter/material.dart';
import 'package:flame/game.dart';
import './game/game.dart';

void main() {
  runApp(const MyApp());
}

// Todo: Use this!
// final _game = SimplePlatformer();

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        body: GameWidget(game: SimplePlatformer()),
      ),
    );
  }
}

SimplePlatformer class:

import 'package:flame/flame.dart';
import 'package:flame/game.dart';
import 'package:flame_tiled/flame_tiled.dart';

class SimplePlatformer extends FlameGame {
  @override
  Future<void>? onl oad() async {
    await Flame.device.fullScreen();
    await Flame.device.setLandscape();

    final level = await TiledComponent.load('level1.tmx', 
    Vector2.all(32));
    add(level);
    return super.onLoad();
  }
}

Level1.tmx file Screenshot

Level1.tmx file Screenshot

Spritesheet.tsx file Screenshot

Spritesheet.tsx file Screenshot

CodePudding user response:

It looks like your XML-file has been corrupted, try to re-export it from Tiled and make sure that you choose to embed tilesets in the export file so that the tmx file doesn't reference external files.

  • Related