makingthematrix / scalaonandroid

A tutorial and examples of how to write Android apps in Scala 2.13 and Scala 3.
GNU General Public License v3.0
169 stars 9 forks source link

Add FXGL simple example #11

Open AlmasB opened 2 years ago

AlmasB commented 2 years ago

Hi @makingthematrix

Following our quick chat on Twitter, please see a standalone example below:

Maven dep coordinates:

<dependency>
    <groupId>com.github.almasb</groupId>
    <artifactId>fxgl</artifactId>
    <version>11.17</version>
</dependency>

Example:

import com.almasb.fxgl.app.GameApplication;
import com.almasb.fxgl.app.GameSettings;
import com.almasb.fxgl.dsl.FXGL;
import javafx.scene.text.Text;

public class UISample extends GameApplication {

    @Override
    protected void initSettings(GameSettings settings) { }

    @Override
    protected void initUI() {
        Text uiText = new Text("Hello World");

        FXGL.addUINode(uiText, 100, 100);
    }

    public static void main(String[] args) {
        launch(args);
    }
}

The example, when executed, will open a 800x600 window with "Hello World" text.

makingthematrix commented 2 years ago

I decided to write a bit more comlicated example so I could try it out together with Gluon Mobile: https://github.com/makingthematrix/scalaonandroid/tree/main/HelloFXGL

It turns out there's no problem with using FXGL from Scala, but there is a problem with using FXGL on Android - there is no support yet for AWT on Android :( I described my work in details in the readme file for HellFXGL (under that link above). Do you think anything can be done about it from your side? Or should I talk to Gluon?

AlmasB commented 2 years ago

FXGL doesn't use AWT per se and does work on Android when using Java. Have you got more info on what exactly the issue is?

Edit: ah, found the readme file, thanks

On Thu, 22 Jul 2021, 1:17 pm Maciej Gorywoda, @.***> wrote:

I decided to write a bit more comlicated example so I could try it out together with Gluon Mobile: https://github.com/makingthematrix/scalaonandroid/tree/main/HelloFXGL

It turns out there's no problem with using FXGL from Scala, but there is a problem with using FXGL on Android - there is no support yet for AWT on Android :( I described my work in details in the readme file for HellFXGL (under that link above). Do you think anything can be done about it from your side? Or should I talk to Gluon?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/makingthematrix/scalaonandroid/issues/11#issuecomment-884866986, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA3NT5X3FDEV73JQ4JO6XILTZAD5HANCNFSM5AVVWO7Q .

AlmasB commented 2 years ago

Right, the issue is with the graalvm version I believe. I tried this with one of the latest stable builds and got the same runtime error. Version 20.2.0 works fine though. As far as I'm aware this is will be fixed eventually, but I wonder what exactly triggers this awt load call -- will check.

Thanks for the Scala example!

makingthematrix commented 2 years ago

@AlmasB : I was able to get the error with only adding FXGL to dependencies, without using it in the code. Maybe one of FXGL dependencies uses AWT?... I wrote about it in a comment here.