使用 Flutter Flame 引擎时出现 XmlParseException 错误
XmlParseException error when using Flutter Flame engine
我正在使用 Flame 游戏引擎在 Flutter 中创建一个游戏 我在平铺的帮助下创建了一个关卡。当我 运行 模拟器中的应用程序时,出现以下错误。
[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
这是代码
主要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>? onLoad() 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 文件截图
Spritesheet.tsx 文件截图
看起来你的 XML-file 已经损坏,尝试从 Tiled re-export 它并确保你选择在导出文件中嵌入 tilesets 这样 tmx 文件就不会引用外部文件。
我正在使用 Flame 游戏引擎在 Flutter 中创建一个游戏 我在平铺的帮助下创建了一个关卡。当我 运行 模拟器中的应用程序时,出现以下错误。
[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
这是代码
主要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>? onLoad() 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 文件截图
Spritesheet.tsx 文件截图
看起来你的 XML-file 已经损坏,尝试从 Tiled re-export 它并确保你选择在导出文件中嵌入 tilesets 这样 tmx 文件就不会引用外部文件。