Remove Resizable mixin (#589)

* Remove Resizable mixin

* Update examples and changelog

* Fixed formatting

* Remove unused import
This commit is contained in:
Lukas Klingsbo
2020-12-22 15:55:29 +01:00
committed by GitHub
parent dfb3a71c4f
commit 18d04c13c0
8 changed files with 47 additions and 37 deletions

View File

@ -2,7 +2,6 @@ import 'package:flame/game.dart';
import 'package:flame/flame.dart';
import 'package:flame/extensions/vector2.dart';
import 'package:flame/components/sprite_component.dart';
import 'package:flame/components/mixins/resizable.dart';
import 'package:flame/text_config.dart';
import 'package:flutter/material.dart' hide Image;
@ -20,8 +19,9 @@ void main() async {
);
}
class AndroidComponent extends SpriteComponent with Resizable {
class AndroidComponent extends SpriteComponent {
static const int SPEED = 150;
Vector2 _gameSize;
int xDirection = 1;
int yDirection = 1;
@ -30,7 +30,7 @@ class AndroidComponent extends SpriteComponent with Resizable {
@override
void update(double dt) {
super.update(dt);
if (gameSize == null) {
if (_gameSize == null) {
return;
}
@ -39,17 +39,23 @@ class AndroidComponent extends SpriteComponent with Resizable {
final rect = toRect();
if ((x <= 0 && xDirection == -1) ||
(rect.right >= gameSize.x && xDirection == 1)) {
(rect.right >= _gameSize.x && xDirection == 1)) {
xDirection = xDirection * -1;
}
y += yDirection * SPEED * dt;
if ((y <= 0 && yDirection == -1) ||
(rect.bottom >= gameSize.y && yDirection == 1)) {
(rect.bottom >= _gameSize.y && yDirection == 1)) {
yDirection = yDirection * -1;
}
}
@override
void onGameResize(Vector2 gameSize) {
super.onGameResize(gameSize);
_gameSize = gameSize;
}
}
class MyGame extends BaseGame {