mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 04:18:25 +08:00
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:
@ -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(
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user