Fix parallax fullscreen bug when game is resized (#887)

* Fix parallax fullscreen bug when game is resized

* Test

Signed-off-by: Lukas Klingsbo <me@lukas.fyi>

* Fix imports

* Remove accidental line

* Re-add mustCallSuper on onGameResize
This commit is contained in:
Lukas Klingsbo
2021-07-29 14:23:37 +02:00
committed by GitHub
parent 1034ca850b
commit 7e4bc1464e
3 changed files with 13 additions and 6 deletions

View File

@ -9,8 +9,7 @@ class ComponentParallaxGame extends BaseGame {
}
}
class MyParallaxComponent extends ParallaxComponent
with HasGameRef<ComponentParallaxGame> {
class MyParallaxComponent extends ParallaxComponent<ComponentParallaxGame> {
@override
Future<void> onLoad() async {
parallax = await gameRef.loadParallax(

View File

@ -15,6 +15,7 @@
- Rename `Camera.cameraSpeed` to `Camera.speed`
- Rename `addShape` to `addHitbox` in `Hitbox` mixin
- Fix bug with Events and Draggables
- Fix parallax fullscreen bug when game is resized
## [1.0.0-releasecandidate.13]
- Fix camera not ending up in the correct position on long jumps

View File

@ -4,6 +4,8 @@ import 'dart:ui';
import 'package:flutter/painting.dart';
import 'package:meta/meta.dart';
import '../../components.dart';
import '../../game.dart';
import '../assets/images.dart';
import '../extensions/vector2.dart';
import '../game/game.dart';
@ -39,7 +41,10 @@ extension ParallaxComponentExtension on Game {
/// A full parallax, several layers of images drawn out on the screen and each
/// layer moves with different velocities to give an effect of depth.
class ParallaxComponent extends PositionComponent {
class ParallaxComponent<T extends BaseGame> extends PositionComponent
with HasGameRef<T> {
@override
bool isHud = true;
bool isFullscreen = true;
Parallax? _parallax;
@ -77,10 +82,12 @@ class ParallaxComponent extends PositionComponent {
@override
void onGameResize(Vector2 size) {
super.onGameResize(size);
if (isFullscreen) {
this.size.setFrom(size);
parallax?.resize(size);
if (!isFullscreen) {
return;
}
final newSize = gameRef.viewport.effectiveSize;
this.size.setFrom(newSize);
parallax?.resize(newSize);
}
@override