{"id":11567,"date":"2023-07-23T23:56:14","date_gmt":"2023-07-23T14:56:14","guid":{"rendered":"https:\/\/www.webcyou.com\/?p=11567"},"modified":"2023-12-20T03:15:29","modified_gmt":"2023-12-19T18:15:29","slug":"flutter-flame%e3%81%a7%e3%82%b2%e3%83%bc%e3%83%a0%e4%bd%9c%e6%88%90-%ef%bc%88%e3%82%ad%e3%83%a3%e3%83%a9%e3%82%af%e3%82%bf%e3%83%bc%e3%81%ae%e7%a7%bb%e5%8b%95%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.webcyou.com\/?p=11567","title":{"rendered":"Flutter &#8211; Flame\u3067\u30b2\u30fc\u30e0\u4f5c\u6210 \uff08\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u79fb\u52d5\uff09"},"content":{"rendered":"\n<p>\u00a0<\/p>\n<p>Flame\u306f\u30012D\u30b2\u30fc\u30e0\u958b\u767a\u306b\u7279\u5316\u3057\u305fFlutter\u306e\u62e1\u5f35\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u306a\u308a\u307e\u3059\u3002Flame\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u7c21\u5358\u306b\u7f8e\u3057\u30442D\u30b2\u30fc\u30e0\u3084\u30a4\u30f3\u30bf\u30e9\u30af\u30c6\u30a3\u30d6\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>Flame\u306f\u3001Flutter\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u9ad8\u901f\u3067\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u826f\u3044\u30b2\u30fc\u30e0\u3092\u958b\u767a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001\u30b7\u30f3\u30d7\u30eb\u306aAPI\u3068\u4f7f\u3044\u3084\u3059\u3055\u304c\u7279\u5fb4\u3067\u3042\u308a\u3001\u30b2\u30fc\u30e0\u958b\u767a\u8005\u306b\u3068\u3063\u3066\u4fbf\u5229\u306a\u30c4\u30fc\u30eb\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u00a0<\/p>\n<p>Flame\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u30b2\u30fc\u30e0\u30eb\u30fc\u30d7\u306e\u7ba1\u7406<\/li>\n<li>\u7d71\u5408\u30bf\u30c3\u30c1\u30a4\u30d9\u30f3\u30c8\u306e\u30b5\u30dd\u30fc\u30c8<\/li>\n<li>\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u306e\u4f5c\u6210<\/li>\n<li>\u7269\u7406\u30a8\u30f3\u30b8\u30f3\u306e\u30b5\u30dd\u30fc\u30c8<\/li>\n<li>\u30ab\u30e1\u30e9\u306e\u5236\u5fa1<\/li>\n<li>\u30d1\u30fc\u30c6\u30a3\u30af\u30eb\u30a8\u30d5\u30a7\u30af\u30c8\u306e\u4f5c\u6210<\/li>\n<\/ul>\n<p>etc..<\/p>\n<p>Flame\u306f\u3001Flutter\u306eWidget\u3068\u3057\u3066\u5b9f\u88c5\u3055\u308c\u3066\u304a\u308a\u3001Flutter\u306e\u4ed6\u306eWidget\u3068\u540c\u69d8\u306b\u3001\u7c21\u5358\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002Flutter\u306eWidget\u306e\u77e5\u8b58\u304c\u3042\u308c\u3070\u3001Flame\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306f\u7c21\u5358\u3067\u3059\u3002<\/p>\n<p>Flame\u306e\u958b\u767a\u306b\u306f\u3001Dart\u8a00\u8a9e\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002Dart\u306f\u3001Flutter\u306e\u958b\u767a\u306b\u4f7f\u7528\u3055\u308c\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3067\u3042\u308a\u3001JavaScript\u3084Java\u3068\u3044\u3063\u305f\u8a00\u8a9e\u306b\u4f3c\u305f\u69cb\u6587\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u3002Dart\u306f\u3001\u9759\u7684\u578b\u4ed8\u3051\u8a00\u8a9e\u3067\u3042\u308a\u3001\u9ad8\u901f\u3067\u5b89\u5168\u306a\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>Flutter\u3068Flame\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u7f8e\u3057\u30442D\u30b2\u30fc\u30e0\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002Flutter\u306f\u3001Android\u3001iOS\u3001Web\u306a\u3069\u306e\u591a\u304f\u306e\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u304a\u308a\u3001Flame\u306f\u305d\u308c\u3089\u306e\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u3067\u52d5\u4f5c\u3057\u307e\u3059\u3002Flame\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001Flutter\u3092\u4f7f\u7528\u3057\u305f2D\u30b2\u30fc\u30e0\u306e\u4f5c\u6210\u304c\u3088\u308a\u7c21\u5358\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><strong>\u516c\u5f0f\u30b5\u30a4\u30c8<\/strong><\/p>\n<p><a href=\"https:\/\/flame-engine.org\/\">https:\/\/flame-engine.org\/<\/a><\/p>\n<p><strong>\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\uff081.8.0\uff09<\/strong><\/p>\n<p><a href=\"https:\/\/docs.flame-engine.org\/1.8.0\/\">https:\/\/docs.flame-engine.org\/1.8.0\/<\/a><\/p>\n<p>Pub.Dev\uff08<strong>1.8.0<\/strong>\uff09<\/p>\n<p><a href=\"https:\/\/pub.dev\/packages\/flame\/install\">https:\/\/pub.dev\/packages\/flame\/install<\/a><\/p>\n<p>\u3068\u3044\u3063\u305f\u611f\u3058\u3067\u3001\u3056\u3063\u3063\u3068\u6982\u8981\u306f\u8ff0\u3079\u305f\u3068\u3053\u308d\u3067\u3001\u5b9f\u969b\u306b\u4f7f\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u4e00\u3064\u306e\u30b2\u30fc\u30e0\u4f5c\u6210\u307e\u3067\u3068\u884c\u304d\u305f\u3044\u3068\u3053\u308d\u3067\u3059\u304c\u3001\u305d\u3046\u306a\u308b\u3068\u7d50\u69cb\u30dc\u30ea\u30e5\u30fc\u30df\u30a3\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u4eca\u56de\u306f\u3068\u308a\u3042\u3048\u305a\u3001\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3092\u8868\u793a\u3057\u52d5\u304b\u3059\u3068\u3053\u308d\u307e\u3067\u3084\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u3067\u306f\u3001\u65e9\u901f\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u8ffd\u52a0\u3057\u3066\u884c\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>pub\u30b3\u30de\u30f3\u30c9\u3092\u7528\u3044\u3066\u3001pub dev\u3088\u308a\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">flutter pub add flame<\/pre>\n<p><strong>pubspec.yaml<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">dependencies:\nflutter:\n  sdk: flutter\nflame: 1.6.0\n \nflutter:\nassets:\n  - assets\/images\/<\/pre>\n<p>\u8ffd\u52a0\u3067\u304d\u3066\u3044\u308c\u3070\u30aa\u30c3\u30b1\u30fc\u3002<\/p>\n<p>\u624b\u52d5\u3067\u8a18\u8ff0\u3057\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">$ flutter pub get<\/pre>\n<p>\u00a0<\/p>\n<p><strong>main.dart<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">import 'package:flame\/game.dart';\nimport 'package:flutter\/material.dart';\nimport '\u3007\u3007.dart';\n \nvoid main() {\n  final game = \u3007\u3007Game();\n  runApp(\n    GameWidget(game: game),\n  );\n}<\/pre>\n<p>flame\u30d1\u30c3\u30b1\u30fc\u30b8\u8ffd\u52a0\u5f8c\u3001import\u3092\u884c\u3044\u3001GameWidget\u3092\u4f7f\u7528\u3057\u3066\u5185\u5bb9\u3092\u4f5c\u6210\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u969b\u306e\u30bd\u30fc\u30b9\u306f\u3053\u306e\u69d8\u306a\u5f62\u3068\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">import 'package:flame\/flame.dart';\nimport 'package:flutter\/material.dart';\n \nimport 'main_game_page.dart';\n \nvoid main() {\n  WidgetsFlutterBinding.ensureInitialized();\n  runApp(const App());\n}\n \nclass App extends StatelessWidget {\n  const App({Key? key}) : super(key: key);\n \n  @override\n  Widget build(BuildContext context) {\n    return const MaterialApp(\n      debugShowCheckedModeBanner: false,\n      title: 'SpriteAnime',\n      home: MainGamePage(),\n    );\n  }\n}<\/pre>\n<p>\u00a0<\/p>\n<p>\u30da\u30fc\u30b8\u5358\u4f4d\u3067\u5207\u308a\u51fa\u305b\u308b\u69d8\u306b\u3001main_game_page.dart\u3092\u8a2d\u3051\u3001StatefulWidget\u3068\u3057\u3066\u4f5c\u6210\u3057\u3001\u5b9f\u969b\u306eflame\u306e\u30b2\u30fc\u30e0\u51e6\u7406\u306b\u95a2\u3057\u3066\u306f\u3001\u66f4\u306bgame.dart\u3068\u30d5\u30a1\u30a4\u30eb\u306e\u5207\u308a\u51fa\u3057\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">import 'package:flutter\/material.dart';\nimport 'package:flutter\/services.dart';\nimport 'package:flame\/palette.dart';\nimport 'package:flame\/game.dart';\nimport 'helpers\/joypad.dart';\n\nimport 'game.dart';\n\nclass MainGamePage extends StatefulWidget {\n  const MainGamePage({Key? key}) : super(key: key);\n\n  @override\n  MainGameState createState() =&gt; MainGameState();\n}\n\nclass MainGameState extends State&lt;MainGamePage&gt; {\n  MainGame game = MainGame();\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n        backgroundColor: const Color.fromRGBO(0, 0, 0, 1),\n        body: Stack(\n          children: [\n            GameWidget(game: game),\n            Align(\n              alignment: Alignment.bottomRight,\n              child: Padding(\n                padding: const EdgeInsets.all(32.0),\n                child:\n                Joypad(onDirectionChanged: game.onJoyPadDirectionChanged),\n              ),\n            )\n          ],\n        )\n    );\n  }\n}<\/pre>\n<p>\u00a0<\/p>\n<p>\u67a0\u7d44\u307f\u306f\u3053\u306e\u69d8\u306a\u5f62\u3067\u3001\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3092\u52d5\u304b\u3059\u305f\u3081\u306b\u3001player component\u3092\u4f5c\u6210\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u00a0<\/p>\n<h4>\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3092\u52d5\u304b\u3059<\/h4>\n<p>\u4eca\u56de\u306e\u30b4\u30fc\u30eb\u3068\u3057\u3066\u3001\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3092\u8868\u793a\u3057\u3001\u79fb\u52d5\u3055\u305b\u308b\u3068\u3053\u308d\u307e\u3067\u884c\u3044\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u30a4\u30e1\u30fc\u30b8\u306f\u4ee5\u4e0b\u306e\u69d8\u306b\u30a6\u30a3\u30f3\u30c9\u30a6\u4e0a\u306b\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u304c\u8868\u793a\u3057\u30012D RPG\u7684\u306a\u52d5\u304d\u3067\u4e0a\u4e0b\u5de6\u53f3\u30ad\u30fc\u30dc\u30fc\u30c9\u306e\u64cd\u4f5c\u3067\u79fb\u52d5\u3067\u304d\u308b\u5f62\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-11569\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2023\/07\/player_move-1024x831.png\" alt=\"\" width=\"527\" height=\"428\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2023\/07\/player_move-1024x831.png 1024w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2023\/07\/player_move-300x243.png 300w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2023\/07\/player_move-768x623.png 768w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2023\/07\/player_move-1536x1246.png 1536w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2023\/07\/player_move.png 1824w\" sizes=\"auto, (max-width: 527px) 100vw, 527px\" \/><\/p>\n<p>\u8aac\u660e\u306f\u3044\u3044\u304b\u3089\u3001\u30bd\u30fc\u30b9\u3092\u5148\u306b\u78ba\u8a8d\u3055\u308c\u305f\u3044\u65b9\u306f\u3001\u30b5\u30f3\u30d7\u30eb\u306e\u30bd\u30fc\u30b9\u306f\u3053\u3061\u3089\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/flame-games\/player_move\">https:\/\/github.com\/flame-games\/player_move<\/a><\/p>\n<p>git clone\u3092\u884c\u3044\u3001fluter run\u30b3\u30de\u30f3\u30c9\u3067\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u00a0<\/p>\n<h4>\u30b9\u30d7\u30e9\u30a4\u30c8\u306e\u8aad\u307f\u8fbc\u307f<\/h4>\n<p>\u4e0a\u65b9\u5411\u306b\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u304c\u79fb\u52d5\u3059\u308b\u969b\u306f\u3001\u4e0a\u65b9\u5411\u306e\u8868\u793a\u3001\u4e0b\u65b9\u5411\u306e\u5834\u5408\u306f\u4e0b\u5411\u304d\u306e\u8868\u793a\u306a\u3069\u5404\u8868\u793a\u4f3c\u5408\u308f\u305b\u3066\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3082\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u3001\u307e\u305a\u306f\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u30b9\u30d7\u30e9\u30a4\u30c8\u753b\u50cf\u306e\u8aad\u307f\u8fbc\u307f\u3092\u884c\u3044\u307e\u3059\u3002\u4f7f\u7528\u3057\u305f\u30b9\u30d7\u30e9\u30a4\u30c8\u753b\u50cf\u306f\u3053\u3061\u3089\u306e\u3082\u306e\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><strong>\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u30b9\u30d7\u30e9\u30a4\u30c8\u753b\u50cf<\/strong><\/p>\n<p>Retro Character Sprite Sheet<\/p>\n<p><a href=\"https:\/\/openclipart.org\/detail\/248259\/retro-character-sprite-sheet\">isaiah658<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-11570\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2023\/07\/player_sp.png\" alt=\"\" width=\"185\" height=\"277\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2023\/07\/player_sp.png 534w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2023\/07\/player_sp-201x300.png 201w\" sizes=\"auto, (max-width: 185px) 100vw, 185px\" \/><\/p>\n<p>\u00a0<\/p>\n<p><strong>\u30b9\u30d7\u30e9\u30a4\u30c8\u8aad\u307f\u8fbc\u307f<\/strong><\/p>\n<p>components\/player.dart \u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3001flame\u306eSpriteAnimationComponent\u3092\u7528\u3044\u3066\u4f5c\u6210\u3059\u308b\u306e\u3067\u3001SpriteAnimationComponent\u3092\u7d99\u627f\u3057\u305fPlayer Class\u3092\u4f5c\u6210\u3002<\/p>\n<p><strong>components\/player.dart<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">class Player extends SpriteAnimationComponent with HasGameRef {<\/pre>\n<pre>\u00a0<\/pre>\n<p>\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3092\u884c\u3046\u3001_loadAnimations\u95a2\u6570\u3092\u4f5c\u6210\u3002<\/p>\n<p>onLoad\u3092override\u3057\u3001_loadAnimations\u95a2\u6570\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">@override\nFuture&lt;void&gt; onLoad() async {\n  super.onLoad();\n  await _loadAnimations().then((_) =&gt; {animation = _standingAnimation});\n}<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"monokai\">Future&lt;void&gt; _loadAnimations() async {\n  final spriteSheet = SpriteSheet(\n    image: await gameRef.images.load('sp_player.png'),\n    srcSize: Vector2(84.0, 110.0),\n  );\n  ....<\/pre>\n<p>Flame\u306eSpriteSheet\u3092\u7528\u3044\u3066\u753b\u50cf\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u969b\u3001Player Class\u3067with HasGameRef\u3092\u884c\u3046\u3053\u3068\u306b\u3088\u3063\u3066\u3001gameRef\u3092\u4f7f\u7528\u53ef\u80fd\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u306e\u3067\u3001gameRef.images.load\u3067\u5bfe\u8c61\u306e\u30b9\u30d7\u30e9\u30a4\u30c8\u753b\u50cf\u3092\u8aad\u307f\u8fbc\u307f\u3057\u3001\u30b9\u30d7\u30e9\u30a4\u30c8\u753b\u50cf\u3092\u30af\u30ea\u30c3\u30d4\u30f3\u30b0\u3059\u308b\u30b5\u30a4\u30ba\u306e\u6307\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p>\u00a0<\/p>\n<h4>\u30b9\u30d7\u30e9\u30a4\u30c8\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3<\/h4>\n<p>\u30b9\u30d7\u30e9\u30a4\u30c8\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u304c\u884c\u308f\u308c\u308b\u3088\u3046\u306b\u3001\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u306e\u8a2d\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p>\u30b9\u30d7\u30e9\u30a4\u30c8\u753b\u50cf\u306e\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306f\u30011\u884c\u76ee\u304c\u4e0b\u5411\u304d\uff08Down\uff09\u30012\u884c\u76ee\u304c\u4e0a\u5411\u304d\uff08Up\uff09\u2026\u3068\u3044\u3046\u5f62\u3068\u306a\u3063\u3066\u304a\u308a\u307e\u3059\u306e\u3067\u3001\u305d\u308c\u306b\u5408\u308f\u305b\u8a2d\u5b9a\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">_runDownAnimation = spriteSheet.createAnimation(row: 0, stepTime: _animationSpeed, to: 4);<\/pre>\n<p>spriteSheet\u306ecreateAnimation\u30e1\u30bd\u30c3\u30c9\u3067\u8a2d\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p>row 0\u306f\u3001\u30b9\u30d7\u30e9\u30a4\u30c8\u753b\u50cf\u306e1\u884c\u76ee\u306b\u8a72\u5f53\u3057\u3001stepTime\u306f \u30b9\u30d7\u30e9\u30a4\u30c8\u753b\u50cf\u304c4step\u3067\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u306e\u30674\u3092\u6307\u5b9a\u3002\u3053\u308c\u3092 _runDownAnimation\u5909\u6570\u3068\u3057\u3066\u6271\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u4ed6\u306e\u65b9\u5411\u3082\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u306e\u901f\u5ea6\u3068\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u79fb\u52d5\u901f\u5ea6\u3092_playerSpeed\u3001_animationSpeed\u306e\u5b9a\u6570\u3068\u3057\u3066\u7528\u610f\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">final double _playerSpeed = 300.0;\nfinal double _animationSpeed = 0.15; \n... \n\nlate final SpriteAnimation _runDownAnimation; \n...<\/pre>\n<h4>\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u79fb\u52d5<\/h4>\n<p>\u30b5\u30f3\u30d7\u30eb\u306b\u306fJoypad\u306b\u3088\u308b\u5b9f\u88c5\u3082\u5165\u3063\u3066\u304a\u308a\u307e\u3059\u304c\u3001\u4eca\u56de\u306e\u8aac\u660e\u3068\u3057\u3066\u306f\u30ad\u30fc\u30dc\u30fc\u30c9\u5165\u529b\u306e\u307f\u3068\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>\u30ad\u30fc\u30dc\u30fc\u30c9\u30a4\u30d9\u30f3\u30c8\u304c\u53d6\u5f97\u3067\u304d\u308b\u3088\u3046\u306b\u3001game.dart\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>MainGame Class\u306fFlameGame\u3092\u7d99\u627f\u3057\u3001KeyboardEvents\u3082\u6271\u3048\u308b\u3088\u3046\u306b with\u3067\u6307\u5b9a\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p><strong>game.dart<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">class MainGame extends FlameGame with KeyboardEvents {<\/pre>\n<p>KeyboardEvents\u306eonKeyEvent\u3092override\u3057\u307e\u3059\u3002RawKeyEvent\u3068Set\uff1cLogicalKeyboardKey\uff1e\u3092\u53d7\u3051\u53d6\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">@override\nKeyEventResult onKeyEvent(RawKeyEvent event, Set&lt;LogicalKeyboardKey&gt; keysPressed) {<\/pre>\n<p>\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u65b9\u5411\uff08\u30ad\u30fc\u30dc\u30fc\u30c9\u304c\u62bc\u3055\u308c\u3066\u3044\u308b\u65b9\u5411\uff09\u306eDirection enum\u3092\u4f5c\u6210\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\">enum Direction { up, down, left, right, none }<\/pre>\n<p>\u4eca\u56de\u306f\u3001\u4e0a: w\u3001\u5de6: a\u3001\u53f3: d\u3001\u4e0b: s\u306e\u30ad\u30fc\u306b\u5272\u308a\u5f53\u3066\u305f\u3044\u306e\u3067\u3001event.logicalKey\u304cLogicalKeyboardKey\u306ekeyA\u3084keyD\u3068\u540c\u7b49\u304b\u3067keyDirection\u5909\u6570\u306b\u683c\u7d0d\u3057\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<p>\u30ad\u30fc\u30a2\u30c3\u30d7\u3059\u308b\uff08\u96e2\u3059\uff09\u3053\u3068\u3067\u3001\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u79fb\u52d5\u3082\u6b62\u3081\u3001\u30a2\u30a4\u30c9\u30eb\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u5272\u5f53\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u3001isKeyDown\u3068keyDirection\u3067\u5224\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u30ad\u30fc\u30a2\u30c3\u30d7\uff08\u62bc\u3055\u308c\u3066\u3044\u306a\u3044\u72b6\u614b\uff09\u3060\u3068\u3001_player.direction\u306b\u306fDirection.none\u304c\u5272\u5f53\u3066\u3089\u308c\u3001\u305d\u308c\u4ee5\u5916\u306f\u305d\u308c\u305e\u308c\u306e\u65b9\u5411\u304c\u5272\u5f53\u3066\u3089\u308c\u307e\u3059\u3002<\/p>\n<p><strong>game.dart<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">@override\nKeyEventResult onKeyEvent(RawKeyEvent event, Set&lt;LogicalKeyboardKey&gt; keysPressed) {\n  final isKeyDown = event is RawKeyDownEvent;\n  Direction? keyDirection = null;\n\n  if (event.logicalKey == LogicalKeyboardKey.keyA) {\n    keyDirection = Direction.left;\n  } else if (event.logicalKey == LogicalKeyboardKey.keyD) {\n    keyDirection = Direction.right;\n  } else if (event.logicalKey == LogicalKeyboardKey.keyW) {\n    keyDirection = Direction.up;\n  } else if (event.logicalKey == LogicalKeyboardKey.keyS) {\n    keyDirection = Direction.down;\n  }\n\n  if (isKeyDown &amp;&amp; keyDirection != null) {\n    _player.direction = keyDirection;\n  } else if (_player.direction == keyDirection) {\n    _player.direction = Direction.none;\n  }\n\n  return super.onKeyEvent(event, keysPressed);\n}<\/pre>\n<p>\u518d\u3073\u3001Player component\u3092\u4fee\u6b63\u3002<\/p>\n<p>\u30b2\u30fc\u30e0\u30b5\u30a4\u30af\u30eb\u306eupdate\u5185\u3067\u3001\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u79fb\u52d5\u306b\u95a2\u3059\u308b\u3053\u3068\u3092\u76e3\u8996\u3057\u305f\u3044\u306e\u3067\u3001<\/p>\n<p>update\u3092override\u3057\u3001\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u79fb\u52d5\u306b\u95a2\u3059\u308b\u95a2\u6570\u3001movePlayer\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<p>movePlayer\u95a2\u6570\u5185\u3067\u3001player\u306edirection\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3001Direction.up\u3084Direction.down\u306a\u3069enum\u3068\u6bd4\u8f03\u3057\u3001\u305d\u308c\u305e\u308c\u306e\u5411\u304d\u306b\u3088\u3063\u3066\u7528\u610f\u3057\u305f\u95a2\u6570\u3092\u5f15\u6570delta\u3092\u6e21\u3057\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001animation = _runUpAnimation;\u3067\u3001Player\u81ea\u8eab\u306eanimation\u3092\u6700\u521d\u306e\u65b9\u306b\u4f5c\u6210\u3057\u305f\u5404\u65b9\u5411\u305d\u308c\u305e\u308c\u65b9\u5411\u5225\u306b\u7528\u610f\u3057\u305f\u3001spriteSheet\u306e\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3092\u6e21\u3057\u3001\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3082\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<p><strong>components\/player.dart<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">@override\nvoid update(double delta) {\n  super.update(delta);\n  movePlayer(delta);\n}\n\nvoid movePlayer(double delta) {\n  switch (direction) {\n    case Direction.up:\n      animation = _runUpAnimation;\n      moveUp(delta);\n      break;\n    case Direction.down:\n      animation = _runDownAnimation;\n      moveDown(delta);\n      break;\n    case Direction.left:\n      animation = _runLeftAnimation;\n      moveLeft(delta);\n      break;\n    case Direction.right:\n      animation = _runRightAnimation;\n      moveRight(delta);\n      break;\n    case Direction.none:\n      animation = _standingAnimation;\n      break;\n  }\n}<\/pre>\n<p>\u00a0<\/p>\n<p>\u4e0a\u3067\u3042\u308c\u3070\u3001moveUp\u95a2\u6570\u3092\u5b9f\u884c\u3002<\/p>\n<p>Player Class\uff08SpriteAnimationComponent\uff09\u306eposition\u3092\u5909\u66f4\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u4e0a\u65b9\u5411\u3067\u3042\u308c\u3070\u3001y\u5ea7\u6a19\u306e\u5024\u304c\u30de\u30a4\u30ca\u30b9\u3068\u306a\u308b\u306e\u3067\u3001delta\u3068_playerSpeed\u3092\u7528\u3044\u3066y\u5ea7\u6a19\u3092\u6e1b\u7b97\u3057\u3001Player\u81ea\u8eab\u3092\u4e0a\u306b\u79fb\u52d5\u3055\u305b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">void moveUp(double delta) { \n  position.add(Vector2(0, delta * -_playerSpeed)); \n}<\/pre>\n<p>\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3092\u5b9f\u969b\u306b\u753b\u9762\u8868\u793a\u3059\u308b\u306b\u306f\u3001Player component\u3092MainGame class\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3068\u3057\u3066\u4fdd\u6301\u3001onLoad\u6642\u306b add\u3057\u307e\u3059\u3002<\/p>\n<p><strong>game.dart<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"dart\" data-enlighter-theme=\"monokai\">final Player _player = Player();\n\n@override\nFuture&lt;void&gt; onLoad() async {\n  super.onLoad();\n  add(_player);\n}<\/pre>\n<p>\u3053\u308c\u3067\u4e00\u901a\u308a\u5fc5\u8981\u6700\u4f4e\u9650\u306e\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u79fb\u52d5\u306e\u5b9f\u88c5\u304c\u3067\u304d\u307e\u3057\u305f\u306e\u3067\u3001\u52d5\u304b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u3068\u3001Flatter\u3001Flame\u3092\u8272\u3005\u89e6\u3063\u3066\u3044\u305f\u306e\u304c4\u30f6\u6708\u524d\u3068\u3001\u6642\u9593\u306e\u6d41\u308c\u306e\u901f\u3055\u3092\u611f\u3058\u3066\u304a\u308a\u3001\u632f\u308a\u8fd4\u308a\u304c\u3066\u3089\u5099\u5fd8\u9332\u3068\u3057\u3066Flatter\u3001Flame\u5468\u308a\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u884c\u3053\u3046\u304b\u3068\u601d\u3063\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<p>4\u30f6\u6708\u524d\u306f Flame\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u30821.6.0\u304c\u6700\u65b0\u3060\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u73fe\u5728\u3067\u306f1.8.1\u304c\u6700\u65b0\u3068\u306a\u3063\u3066\u304a\u308a\u3001\u3053\u3061\u3089\u306e\u958b\u767a\u306e\u901f\u3055\u3082\u611f\u3058\u308c\u307e\u3059\u3002<\/p>\n<p>\u958b\u767a\u3082\u6d3b\u767a\u306b\u884c\u308f\u308c\u3066\u3044\u3066\u3053\u308c\u304b\u3089\u3082\u671f\u5f85\u3067\u304d\u305d\u3046\u306aFlutter\u306e\u30b2\u30fc\u30e0\u30a8\u30f3\u30b8\u30f3\u3068\u306a\u3063\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<p>\u6b21\u56de\u306f\u3001\u30de\u30c3\u30d7\u79fb\u52d5\u3084\u30b2\u30fc\u30e0\u4f5c\u6210\u306b\u3064\u3044\u3066\u89e6\u308c\u3089\u308c\u308c\u3070\u3068\u601d\u3063\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u3041\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 Flame\u306f\u30012D\u30b2\u30fc\u30e0\u958b\u767a\u306b\u7279\u5316\u3057\u305fFlutter\u306e\u62e1\u5f35\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u306a\u308a\u307e\u3059\u3002Flame\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u7c21\u5358\u306b\u7f8e\u3057\u30442D\u30b2\u30fc\u30e0\u3084\u30a4\u30f3\u30bf\u30e9\u30af\u30c6\u30a3\u30d6\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 Flame\u306f\u3001Flut [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":11568,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[295],"tags":[310,301,188,166,37,47,178,78,118],"class_list":["post-11567","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-flutter","tag-flame","tag-flutter","tag-game","tag-iphone","tag-iphone-","tag-javascript-2","tag-178","tag-78","tag-118"],"_links":{"self":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/11567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11567"}],"version-history":[{"count":39,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/11567\/revisions"}],"predecessor-version":[{"id":11622,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/11567\/revisions\/11622"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/media\/11568"}],"wp:attachment":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}