-
-
Notifications
You must be signed in to change notification settings - Fork 899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Animated tile support! #1930
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8f4aae5
feat: Animated tile support!
jtmcdole 3383922
Fixes lint and markdown
jtmcdole 370f0e1
WIP: More tests. Not ready yet
jtmcdole 547cadb
Fix sizes!
jtmcdole 136a19c
Cleanup goldens & testing to use component.size.
jtmcdole e91d939
these are wrong
jtmcdole 86781f3
Fixes:
jtmcdole 5faa065
melos
jtmcdole 094794d
Perforamnce tweak - move time tracking to frames
jtmcdole 6e9d5b7
One more optimization: one cache for all TileFrames
jtmcdole d094f33
Reviewer comments
jtmcdole 6c17b95
Examples
jtmcdole fb92af3
Remove tap dector copy-pasta
jtmcdole File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<tileset version="1.9" tiledversion="1.9.2" name="0x72_DungeonTilesetII_v1.4" tilewidth="16" tileheight="16" tilecount="1024" columns="32"> | ||
<image source="../images/0x72_DungeonTilesetII_v1.4.png" width="512" height="512"/> | ||
<tile id="36"> | ||
<animation> | ||
<frame tileid="36" duration="180"/> | ||
<frame tileid="37" duration="180"/> | ||
<frame tileid="38" duration="180"/> | ||
</animation> | ||
</tile> | ||
<tile id="68"> | ||
<animation> | ||
<frame tileid="68" duration="180"/> | ||
<frame tileid="69" duration="180"/> | ||
<frame tileid="70" duration="180"/> | ||
</animation> | ||
</tile> | ||
<tile id="100"> | ||
<animation> | ||
<frame tileid="100" duration="180"/> | ||
<frame tileid="101" duration="180"/> | ||
<frame tileid="102" duration="180"/> | ||
</animation> | ||
</tile> | ||
<tile id="132"> | ||
<animation> | ||
<frame tileid="132" duration="180"/> | ||
<frame tileid="133" duration="180"/> | ||
<frame tileid="134" duration="180"/> | ||
</animation> | ||
</tile> | ||
<tile id="356"> | ||
<animation> | ||
<frame tileid="353" duration="70"/> | ||
<frame tileid="354" duration="70"/> | ||
<frame tileid="355" duration="70"/> | ||
<frame tileid="356" duration="70"/> | ||
<frame tileid="355" duration="70"/> | ||
<frame tileid="354" duration="70"/> | ||
</animation> | ||
</tile> | ||
<tile id="368"> | ||
<animation> | ||
<frame tileid="44" duration="130"/> | ||
<frame tileid="45" duration="130"/> | ||
<frame tileid="46" duration="130"/> | ||
<frame tileid="47" duration="130"/> | ||
<frame tileid="48" duration="130"/> | ||
</animation> | ||
</tile> | ||
<tile id="496"> | ||
<animation> | ||
<frame tileid="488" duration="210"/> | ||
<frame tileid="489" duration="210"/> | ||
<frame tileid="490" duration="210"/> | ||
<frame tileid="491" duration="210"/> | ||
</animation> | ||
</tile> | ||
<tile id="627"> | ||
<animation> | ||
<frame tileid="627" duration="210"/> | ||
<frame tileid="628" duration="210"/> | ||
<frame tileid="629" duration="210"/> | ||
<frame tileid="628" duration="210"/> | ||
</animation> | ||
</tile> | ||
<tile id="659"> | ||
<animation> | ||
<frame tileid="659" duration="210"/> | ||
<frame tileid="660" duration="210"/> | ||
<frame tileid="661" duration="210"/> | ||
</animation> | ||
</tile> | ||
</tileset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<map version="1.9" tiledversion="1.9.2" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="1"> | ||
<tileset firstgid="1" source="0x72_DungeonTilesetII_v1.4.tsx"/> | ||
<layer id="3" name="ground" width="10" height="10" locked="1"> | ||
<data encoding="base64" compression="gzip"> | ||
H4sIAAAAAAAACmNgoAw0Y6FHMfkYAK7z31GQAQAA | ||
</data> | ||
</layer> | ||
<layer id="1" name="walls" width="10" height="10"> | ||
<data encoding="base64" compression="gzip"> | ||
H4sIAAAAAAAACp3Q7QmDMBSF4ZuELFIVF9FNdBQXae0i4scegnYNXzDgKfSH9MJDksPh/og3My+i0Dw4s4ddiqTVjI6HTp10krkfPZ3xZu/uvn97Zeo+OV/o8XbfvQzBTgP3GQsmyaP8XYOV944PNuRkFTIcCfCt35ABAAA= | ||
</data> | ||
</layer> | ||
<layer id="4" name="stuff" width="10" height="10"> | ||
<data encoding="base64" compression="gzip"> | ||
H4sIAAAAAAAACmNgoA0oYaKNuamMuOW2IqmBYRgwQ2JfxWHeFKCbw/CYTw8AANEJHwqQAQAA | ||
</data> | ||
</layer> | ||
</map> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
examples/lib/stories/tiled/flame_tiled_animation_example.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:flame/game.dart'; | ||
import 'package:flame_tiled/flame_tiled.dart'; | ||
|
||
class FlameTiledAnimationExample extends FlameGame { | ||
static const String description = ''' | ||
Loads and displays an animated Tiled map. | ||
'''; | ||
|
||
late final TiledComponent map; | ||
|
||
@override | ||
Future<void> onLoad() async { | ||
map = await TiledComponent.load('dungeon.tmx', Vector2.all(32)); | ||
add(map); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:dashbook/dashbook.dart'; | ||
import 'package:examples/commons/commons.dart'; | ||
import 'package:examples/stories/tiled/flame_tiled_animation_example.dart'; | ||
|
||
import 'package:flame/game.dart'; | ||
|
||
void addTiledStories(Dashbook dashbook) { | ||
dashbook.storiesOf('Tiled').add( | ||
'Flame Tiled Animation', | ||
(_) => GameWidget(game: FlameTiledAnimationExample()), | ||
codeLink: baseLink('effects/flame_tiled_animation_example.dart'), | ||
info: FlameTiledAnimationExample.description, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'dart:ui' show Rect; | ||
|
||
/// A mutable version of [Rect] for tile map animations. | ||
class MutableRect extends Rect { | ||
/// Construct a rectangle from its left, top, right, and bottom edges. | ||
MutableRect.fromLTRB(this.left, this.top, this.right, this.bottom) | ||
: super.fromLTRB(left, top, right, bottom); | ||
|
||
/// Create a new instance from [other]. | ||
factory MutableRect.fromRect(Rect other) => | ||
MutableRect.fromLTRB(other.left, other.top, other.right, other.bottom); | ||
|
||
/// The offset of the left edge of this rectangle from the x axis. | ||
@override | ||
double left; | ||
|
||
/// The offset of the top edge of this rectangle from the y axis. | ||
@override | ||
double top; | ||
|
||
/// The offset of the right edge of this rectangle from the x axis. | ||
@override | ||
double right; | ||
|
||
/// The offset of the bottom edge of this rectangle from the y axis. | ||
@override | ||
double bottom; | ||
|
||
/// Update with [other]'s dimensions. | ||
void copy(Rect other) { | ||
left = other.left; | ||
top = other.top; | ||
right = other.right; | ||
bottom = other.bottom; | ||
} | ||
|
||
/// Convert to immutable rectangle. | ||
Rect toRect() => Rect.fromLTRB(left, top, right, bottom); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️