场景
场景就是普通的Widget,我们来看下GameScene类的定义:
class GameScene extends StatefulWidget {
final int map;
GameScene({this.map = 1});
@override
_GameSceneState createState() => _GameSceneState();
}
class _GameSceneState extends State with TickerProviderStateMixin {
/// 创建主场景
_GameSceneState();
/// 初始化状态
@override
void initState() {
super.initState();
/// 强制横屏
SystemChrome.setPreferredOrientations(
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
}
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
return Stack(fit: StackFit.expand, children:[
Positioned(
left: 20,
top: MediaQuery.of(context).padding.top + 20,
child: Text(
"Devilf",
style: TextStyle(
color: Colors.white,
fontSize: 14,
),
),
),
]);
});
}
}
在main.dart其中这个场景:
main() async {
/// 游戏场景
GameScene gameScene = GameScene();
/// 运行游戏
runApp(MyApp(gameScene));
}
/// 主控件
class MyApp extends StatelessWidget {
GameScene _gameScene;
MyApp(this._gameScene);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Devilf',
theme: ThemeData(
primarySwatch: Colors.deepOrange,
),
home: Scaffold(
body: _gameScene,
),
);
}
}
本站内容来源于作者发布和网络转载,如有版权相关问题请及时与我们取得联系,我们将立即删除。