flame-engine / flame

A Flutter based game engine.
https://flame-engine.org
MIT License
9.29k stars 913 forks source link

TextBoxComponent example code error text_box_component.dart:140:36: Error: A value of type 'Future<Image>' can't be assigned to a variable of type 'Image'. #72

Closed pgainullin closed 5 years ago

pgainullin commented 5 years ago

Code:

import 'dart:ui';
import 'package:flame/palette.dart';
import 'package:flame/components/text_box_component.dart';
import 'package:flame/text_config.dart';

TextConfig regular = TextConfig(color: BasicPalette.white.color);
TextConfig tiny = regular.withFontSize(12.0);

class HelpView extends TextBoxComponent {
  HelpView(String text)
      : super(text,
      config: tiny, boxConfig: const TextBoxConfig(timePerChar: 0.05));

  @override
  void drawBackground(Canvas c) {
    final Rect rect = Rect.fromLTWH(0, 0, width, height);
    c.drawRect(rect, Paint()..color = const Color(0xFFFF00FF));
    c.drawRect(
        rect.deflate(boxConfig.margin),
        Paint()
          ..color = BasicPalette.black.color
          ..style = PaintingStyle.stroke);
  }
}

Error:

pub.dartlang.org/flame-0.10.2/lib/components/text_box_component.dart:140:36: Error: A value of type 'Future' can't be assigned to a variable of type 'Image'.

  • 'Future' is from 'dart:async'.
  • 'Image' is from 'dart:ui'. Try changing the type of the left hand side, or casting the right hand side to 'Image'. return recorder.endRecording().toImage(width.toInt(), height.toInt()); ^ Compiler failed on D:\OneDrive\dev\galaxygame\lib\main.dart Finished with error: Gradle task assembleDebug failed with exit code 1
luanpotter commented 5 years ago

Hi, @pgainullin , thanks for the report!

What version of flutter/dart are you using?

This is probably caused by a recent change in the Flutter SDK that required refactoring of flame, using a new API that used to return Image and now returns a Future<Image>.

Currently we are using Flutter version 1.2.0 here, though that's up to debate (which version we should support).

pgainullin commented 5 years ago

Thanks for quick response. I'm using 1.2.1:

Flutter 1.2.1 • channel stable • https://github.com/flutter/flutter.git Framework • revision 8661d8aecd (7 weeks ago) • 2019-02-14 19:19:53 -0800 Engine • revision 3757390fa4 Tools • Dart 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)

luanpotter commented 5 years ago

Please try to update to flutter version 1.4.10; it should work on the newer versions :) You can do that by changing the flutter channel to anything greater than stable, I believe.

pgainullin commented 5 years ago

I'm clearly doing something wrong but I'm getting a different error at compile in this case:

flame-0.10.3/lib/svg.dart:26:17: Error: Too few positional arguments: 3 required, 2 given. svgRoot.draw(canvas, null);

I was only able to solve it by going back to Flame v. 0.10.2 which then results in the original error related to the TextBoxComponent.

luanpotter commented 5 years ago

Fixed on 0.10.4; @pgainullin , would you please test that for us? Thanks!

pgainullin commented 5 years ago

Thanks! this works without errors though I can't seem to be able to get it to render anything using the pattern

(MyTextBox instance).render(canvas)

within my game render function. best I can do is force it to drawBackground by adding it to the render override of MyTextBox.

luanpotter commented 5 years ago

Hi, @pgainullin! Have you seen the example app called text inside the docs/examples folder? Does that app work? Could you compare and see the differences? Or show your code that is not working and why? So that we can better understand the problem...

luanpotter commented 5 years ago

Hi, @pgainullin , we tested here with the latest versions of flame, the docs/examples/text example is working fine. Could you please either refer to that to see if something is wrong or provide your code that you claim is not working?

pgainullin commented 5 years ago

Hi,

Thanks very much - I'm sure I'll figure it out but I'm travelling for a few weeks now and won't be able to test. Thanks again for being so responsive!

On Mon, 22 Apr 2019 at 01:10, Luan Nico notifications@github.com wrote:

Hi, @pgainullin https://github.com/pgainullin , we tested here with the latest versions of flame, the docs/examples/text example is working fine. Could you please either refer to that to see if something is wrong or provide your code that you claim is not working?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/luanpotter/flame/issues/72#issuecomment-485267366, or mute the thread https://github.com/notifications/unsubscribe-auth/AGJSBXY3KGBMPENQWKKQYP3PRSNXZANCNFSM4HD2DYRQ .

--

Pjotr Gainullin +65 9669 8721 pgainullin@gmail.com

erickzanardo commented 5 years ago

This has been inactive for some time now and the issue was resolved on a couple of versions earlier.

I will be closing this, but feel free to open a new issue if you still have problems @pgainullin.