forked from Brixto/flame_texturepacker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.dart
More file actions
75 lines (62 loc) · 1.67 KB
/
main.dart
File metadata and controls
75 lines (62 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame_texturepacker/flame_texturepacker.dart';
import 'package:flutter/material.dart';
main() {
final myGame = MyGame();
runApp(
GameWidget(
game: myGame,
),
);
}
class MyGame extends FlameGame {
@override
Future<void> onLoad() async {
super.onLoad();
// Load the atlasMap.
final atlas = await fromAtlas('FlameAtlasMap.atlas');
// Get a list of sprites ordered by their index
final walkingSprites = atlas.findSpritesByName('robot_walk');
// Create animation with the list of sprites
final walkingAnimation = SpriteAnimation.spriteList(
walkingSprites,
stepTime: 0.1,
loop: true,
);
// Get individual sprites by name
final jumpSprite = atlas.findSpriteByName('robot_jump')!;
final fallSprite = atlas.findSpriteByName('robot_fall')!;
final idleSprite = atlas.findSpriteByName('robot_idle')!;
// Get the list of all sprites in the sprite sheet
final allSprites = atlas.sprites; // ignore: unused_local_variable
add(
SpriteComponent(
sprite: jumpSprite,
position: Vector2(200, 100),
size: Vector2(72, 96),
),
);
add(
SpriteComponent(
sprite: fallSprite,
position: Vector2(300, 100),
size: Vector2(72, 96),
),
);
add(
SpriteComponent(
sprite: idleSprite,
position: Vector2(400, 100),
size: Vector2(72, 96),
),
);
add(
SpriteAnimationComponent(
animation: walkingAnimation,
position: Vector2(300, 200),
size: Vector2(72, 96),
),
);
}
}