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
@override | |
Color backgroundColor() => const Color(0x00000000); |
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
void main() { | |
runApp( | |
Background( | |
child: GameWidget(game: TiledGame()), | |
), | |
); | |
} |
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
import 'dart:async'; | |
import 'dart:ui' as ui; | |
import 'package:flame_tiled_example/background_painter.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/services.dart'; | |
class Background extends StatefulWidget { | |
const Background({required this.child, super.key}); |
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
import 'dart:ui' as ui; | |
import 'package:flutter/material.dart'; | |
class BackgroundPainter extends CustomPainter { | |
BackgroundPainter({required ui.Image backgroundImage}) { | |
_backgroundImage = backgroundImage; | |
} | |
late ui.Image _backgroundImage; |
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
@override | |
Future<void> onTapUp(TapUpInfo info) async { | |
final tappedCel = _getTappedCell(info); | |
final spriteComponent = SpriteComponent( | |
size: Vector2.all(64.0), | |
sprite: await Sprite.load('unit_infantry_germany.png'), | |
) | |
..anchor = Anchor.center | |
..position = Vector2(tappedCel.center.dx, tappedCel.center.dy) |
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
// _getTappedCell(info); | |
estimateCallTime<TileInfo>(() { | |
return _getTappedCell(info); | |
}, | |
); |
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
import 'dart:developer' as developer; | |
T estimateCallTime<T>(T Function() action) { | |
final stopwatch = Stopwatch()..start(); | |
final result = action(); | |
developer.log('The function executed in ${stopwatch.elapsed}'); | |
return result; | |
} |
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
class TileInfo { | |
TileInfo({ | |
required this.center, | |
required this.row, | |
required this.col, | |
}); | |
final Offset center; | |
final int row; | |
final int col; |
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
@override | |
void onScaleEnd(ScaleEndInfo info) { | |
_checkScaleBorders(); | |
_checkDragBorders(); | |
} | |
void _checkScaleBorders() { | |
camera.viewfinder.zoom = camera.viewfinder.zoom.clamp(_minZoom, _maxZoom); | |
} |
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
@override | |
void onScaleUpdate(ScaleUpdateInfo info) { | |
final currentScale = info.scale.global; | |
if (currentScale.isIdentity()) { | |
_processDrag(info); | |
} else { | |
_processScale(info, currentScale); | |
} | |
} |
NewerOlder