mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
Fixing example and restoring SpriteComponent
This commit is contained in:
@ -1,11 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 105">
|
|
||||||
<g fill="#97C024" stroke="#97C024" stroke-linejoin="round" stroke-linecap="round">
|
|
||||||
<path d="M14,40v24M81,40v24M38,68v24M57,68v24M28,42v31h39v-31z" stroke-width="12"/>
|
|
||||||
<path d="M32,5l5,10M64,5l-6,10 " stroke-width="2"/>
|
|
||||||
</g>
|
|
||||||
<path d="M22,35h51v10h-51zM22,33c0-31,51-31,51,0" fill="#97C024"/>
|
|
||||||
<g fill="#FFF">
|
|
||||||
<circle cx="36" cy="22" r="2"/>
|
|
||||||
<circle cx="59" cy="22" r="2"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 471 B |
BIN
doc/examples/debug/assets/images/android.png
Normal file
BIN
doc/examples/debug/assets/images/android.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
@ -1,8 +1,7 @@
|
|||||||
import 'package:flame/game.dart';
|
import 'package:flame/game.dart';
|
||||||
import 'package:flame/flame.dart';
|
import 'package:flame/flame.dart';
|
||||||
import 'package:flame/svg.dart';
|
|
||||||
import 'package:flame/position.dart';
|
import 'package:flame/position.dart';
|
||||||
import 'package:flame/components/component.dart' show SvgComponent;
|
import 'package:flame/components/component.dart';
|
||||||
import 'package:flame/components/mixins/resizable.dart';
|
import 'package:flame/components/mixins/resizable.dart';
|
||||||
import 'package:flame/text_config.dart';
|
import 'package:flame/text_config.dart';
|
||||||
|
|
||||||
@ -16,12 +15,12 @@ void main() async {
|
|||||||
myGame.start();
|
myGame.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
class AndroidComponent extends SvgComponent with Resizable {
|
class AndroidComponent extends SpriteComponent with Resizable {
|
||||||
static const int SPEED = 150;
|
static const int SPEED = 150;
|
||||||
int xDirection = 1;
|
int xDirection = 1;
|
||||||
int yDirection = 1;
|
int yDirection = 1;
|
||||||
|
|
||||||
AndroidComponent() : super.fromSvg(100, 100, Svg('android.svg'));
|
AndroidComponent() : super.square(100, 'android.png');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void update(double dt) {
|
void update(double dt) {
|
||||||
|
|||||||
@ -18,4 +18,4 @@ dev_dependencies:
|
|||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
assets:
|
assets:
|
||||||
- assets/android.svg
|
- assets/images/android.png
|
||||||
|
|||||||
@ -171,3 +171,36 @@ abstract class PositionComponent extends Component {
|
|||||||
_effects.removeWhere((e) => e.hasFinished());
|
_effects.removeWhere((e) => e.hasFinished());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [PositionComponent] that renders a single [Sprite] at the designated position, scaled to have the designated size and rotated to the designated angle.
|
||||||
|
///
|
||||||
|
/// This is the most commonly used child of [Component].
|
||||||
|
class SpriteComponent extends PositionComponent {
|
||||||
|
Sprite sprite;
|
||||||
|
Paint overridePaint;
|
||||||
|
|
||||||
|
SpriteComponent();
|
||||||
|
|
||||||
|
SpriteComponent.square(double size, String imagePath)
|
||||||
|
: this.rectangle(size, size, imagePath);
|
||||||
|
|
||||||
|
SpriteComponent.rectangle(double width, double height, String imagePath)
|
||||||
|
: this.fromSprite(width, height, Sprite(imagePath));
|
||||||
|
|
||||||
|
SpriteComponent.fromSprite(double width, double height, this.sprite) {
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void render(Canvas canvas) {
|
||||||
|
prepareCanvas(canvas);
|
||||||
|
sprite.render(canvas,
|
||||||
|
width: width, height: height, overridePaint: overridePaint);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool loaded() {
|
||||||
|
return sprite != null && sprite.loaded() && x != null && y != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user