Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
dcejvan
@dcejvan
image.png
What i currently have: The bullet stops at wherever I shoot.
Benny Chao
@Bnyaoo
Hey @AlmasB, is there anyway to connect my FXGL project with a JavaFX JDBC application?
nbulgarides42
@nbulgarides42

Hi Almas, long time since I've asked you a question. I hope you are doing well. I am trying to sue your networking API and the basic example from the Wiki does not work for me. I created two classes, ServerTest1 and TestClient1 that each have the 7 or so lines of code from your example. When I run them, the server appears to broadcast successfully, but the client never receives the message and reacts.`private Server<Bundle> mainServer;

`
public ServerTest1(int portNumber){

    var server = FXGL.getNetService().newTCPServer(portNumber);

    this.mainServer = server;

    server.startAsync();
}`

public void sendTestMessage(){
    var data = new Bundle("testBundle");
    data.put("helloworld", "The server is running!");

    this.mainServer.broadcast(data);
    System.out.println("Data broadcasted");
}    Client networkClient;
public TestClient1 (){
    loadClient();
}`

private void loadClient() {
    var client = FXGL.getNetService().newTCPClient("localhost", 55555);
    this.networkClient = client;

    client.setOnConnected(connection -> {
        connection.addMessageHandlerFX((conn, message) -> {
            System.out.println("Msg occured");
            String msg = message.get("helloworld");
            System.out.println(msg);
        });
    });
    this.networkClient.connectAsync();
}`
Anna Chen
@theannachen
hey guys i have a quick question as a beginner. How do i make something not able to pass through another entity? Right now, I have tried adding the .collidable() to the entity in the entity factory, but it's still going through another entity that also has that on. is there another way to approach this?
Almas Baimagambetov
@AlmasB
@dcejvan Hi, if you wish to use translateTowards() then you need a point that is off-screen, otherwise you will get the same behaviour as you are getting now. Alternatively, use ProjectileComponent.
@Bnyaoo Hi, there is nothing built-in for jdbc. So it would be like connecting any other application.

@nbulgarides42 Hi, there is nothing in your example that suggests an issue. Some questions that may help you troubleshoot.

Is your portNumber variable set to 55555? Is your data broadcast after the client has connected? Do you know if the client is connecting at all (perhaps print a message on connected)?

1 reply
Almas Baimagambetov
@AlmasB
@theannachen Hi, can you provide a bit more context to this please. I assume you mean entities with PhysicsComponent attached? If yes, please see this platformer example for some reference code. If not, then entities are not part of the physics world and hence there is no built-in way to prevent entities from passing through each other. You'd need some custom behaviour based on your gameplay.
Anna Chen
@theannachen
Thank you os much! I will take a look into it and let you know if i have any more questions
dcejvan
@dcejvan
@AlmasB I see. I was using the ProjectileComponment before hand, but realized I wanted to incorporate other properties for the bullet where making a new component just would've been easier. I am planning on using the slope to create a new point of the screen. Thank you!
Almas Baimagambetov
@AlmasB
@nbulgarides42 you can't have more than one server listening on a single port if that's what you mean.
nbulgarides42
@nbulgarides42
Hi Almas, I hope you are doing well. I have a question about how TimerActions interact with loops: If I have a timer action that runs at an interval of say 5 seconds, and the timer loops through something that lets say takes 6 seconds, what happens? If the loop behavior takes 4 seconds then the results are obvious and the interval repeat will simply occur at second 5 and go through the list again. If the loop however is longer to process than the timer interval, this is where I do not know how the mechanics resolve. Do you have any information on this? Thanks.
Rafael Ibasco
@ribasco
Hello, I am currently testing the RopeJointSample (v17.1) in embedded mode. I noticed that if I use the TabPane as the root node then pass the FXGLPane to it, the mouse input events doesn't seem to register. Is this a bug?
public class EmbeddedTest extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        var game = GameApplication.embeddedLaunch(new RopeJointSample());

        //Test 1: Mouse button not registering
        var rootNode = new TabPane();
        rootNode.getTabs().add(new Tab("Game", game));

        //Test 2: Mouse button registering
        /*var rootNode = new VBox();
        rootNode.getChildren().add(game);*/

        var scene = new Scene(rootNode); //Test 3: Mouse button not registering

        //var scene = new Scene(game);  //Test 4: Input working

        stage.setScene(scene);
        stage.show();
    }
}
dcejvan
@dcejvan
image.png
Hey @AlmasB , I've been looking to make an EnemyComponent that would contain custom types of enemy types, different health, etc. However, I am not sure what would be the best way to move this component as a result of this. I have tried to use translateTowards, but if you move the component only horizontally, it weirdly jitters. Do you have any ideas on what to do?
dcejvan
@dcejvan
Solved.
dcejvan
@dcejvan
image.png
Got a question @AlmasB , I need some help on being able to to update values of components for entities. I have some rows and columns of Enemys here:
image.png
I've made an EnemyComponent that is built into the Entity as it is spawned. However, I am not sure how to update these values; depending on the row, i'd like for the enemies to have different attacks, speed, and more.
Do you have any ideas? Please let me know. Thank you!
Almas Baimagambetov
@AlmasB
@nbulgarides42 Hi, timers tick and check for interval every frame. Each frame runs at the rate of engine tick (by default 60 frames per second). So if a single frame takes longer than the timer interval to compute (in a well designed app this shouldn't happen as all heavy tasks should be run in a background thread), then the timer would effectively run every frame.
@ribasco Hi, it is not necessarily a bug as it probably works according to the JavaFX scene graph focus rules. So ultimately the way forward depends on your use case and what behaviour you need. Then you can start thinking about how to achieve it. In the case above, perhaps shifting focus to the correct node would help. You'd need to refer to the JavaFX documentation on focus rules and what nodes do and do not receive input events.
Almas Baimagambetov
@AlmasB
@dcejvan Hi, I assume your methods that create entities are in a factory. Then you'd spawn an entity using FXGL.spawn("entityType"). If that is the case, you can pass in another value into this method, namely the SpawnData object, which can contain specific information for a given entity. Here's a quick example:
for (y in ..) {
  for (x in ..) {
    FXGL.spawn("enemy", new SpawnData(x * cellSize, y * cellSize).put("attack", x * 10);
  }
}
Finally, within the method that creates the entity, i.e. where you have entityBuilder(data)..., the data object has all the information you passed in during the call to spawn above. So you can do something like:
int attack = data.getInt("attack");

entityBuilder(data)
...
with(new EnemyComponent(..., attack));
dcejvan
@dcejvan
Thank you so much! That makes more sense now. How would I be able to update the values within the EnemyComponent for the entity? For example, the health. Sorry, I am just a bit unsure about that. @AlmasB
nbulgarides42
@nbulgarides42
@AlmasB Thank you for your answer, I would like to provide a bit more context on what I am doing to make sure that me using the FXGL game timer is appropriate. I successfully have server / client architecture running, and on a separate thread I use the FXGL game timer to iterate through connected clients and process messages from the client. Java sockets are non-blocking and have a read line function so the solution appears to work for now, but I am unsure as to how the FXGL game timer interacts with being on a separate thread due to the FXGL timer running on the main game thread from my understanding. Do you think using the FXGL timer for the convenient syntax on a background thread would cause issues, or should I simply use the built-in Java timer? For the server side application the only use of FXGL currently is the timer action, though on the client I use FXGL for a variety of tasks. But yeah, in summary, I am not sure how the FXGL timer interacts with background threads when the iteration through a process on a background thread may (or may not) take longer than the interval on the thread
dcejvan
@dcejvan
Hey @AlmasB , got another question. How do I replay particle effects, such as the explosion emitter? I'm Confused on what function to call in order to do that if any. Thank you!
dcejvan
@dcejvan
Hey hey @AlmasB . Got another question (Sorry lol). How would I be able to add a debounce for certain functions? For example, in my initInput function, I have a function attached to my left mouse that fires a bullet upwards. I'd like for there to be some sort of debounce so you cannot spam click this. How would I be able to do this? Thank you.
dcejvan
@dcejvan

Hey hey @AlmasB . Got another question (Sorry lol). How would I be able to add a debounce for certain functions? For example, in my initInput function, I have a function attached to my left mouse that fires a bullet upwards. I'd like for there to be some sort of debounce so you cannot spam click this. How would I be able to do this? Thank you.

Resolved.

Hey @AlmasB , got another question. How do I replay particle effects, such as the explosion emitter? I'm Confused on what function to call in order to do that if any. Thank you!

Resolved.

Thank you so much! That makes more sense now. How would I be able to update the values within the EnemyComponent for the entity? For example, the health. Sorry, I am just a bit unsure about that. @AlmasB

Resolved.

image.png
While those are resolved, I do have another question @AlmasB , I currently have my enemies as displayed earlier moving in the onUpdate function within their component. Rather than using .translateX, I'd like to use animationBuilder instead, to give me more leeway on how I'd like for the movement to look like. However, I'm quite confused on how to use it. Heres the current code:
Rather than this, i'd like to change this into an animation using animationBuilder. Do you have any ideas on how to achieve this? Thank you.
nbulgarides42
@nbulgarides42

Has anyone here tried compiling FXGL for MacOS? I tried to do this and with great difficulty I found some lines to add to Maven that made it that finally my Jar would run on both Windows and MacOs. However, after starting up and showing the initial pane, an exception occurred that appears to relate to the FXGL sound asset loader's ability to be cross platform. It works on windows but on MacOS I got this exception,

java.lang.UnsatisfiedLinkError: no glib-lite in java.library.path: /Users/nicolasbulgarides/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.

at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2434)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:848)
at java.base/java.lang.System.loadLibrary(System.java:2015)
at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:166)
at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:54)
at com.sun.media.jfxmediaimpl.NativeMediaManager.lambda$new$0(NativeMediaManager.java:110)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
at com.sun.media.jfxmediaimpl.NativeMediaManager.<init>(NativeMediaManager.java:107)
at com.sun.media.jfxmediaimpl.NativeMediaManager$NativeMediaManagerInitializer.<clinit>(NativeMediaManager.java:78)
at com.sun.media.jfxmediaimpl.NativeMediaManager.getDefaultInstance(NativeMediaManager.java:90)
at com.sun.media.jfxmedia.MediaManager.canPlayProtocol(MediaManager.java:78)
at com.sun.media.jfxmedia.locator.Locator.<init>(Locator.java:239)
at com.sun.media.jfxmediaimpl.NativeMediaAudioClip.<init>(NativeMediaAudioClip.java:53)
at com.sun.media.jfxmediaimpl.NativeMediaAudioClip.load(NativeMediaAudioClip.java:63)
at com.sun.media.jfxmediaimpl.AudioClipProvider.load(AudioClipProvider.java:66)
at com.sun.media.jfxmedia.AudioClip.load(AudioClip.java:135)
at javafx.scene.media.AudioClip.<init>(AudioClip.java:83)

at
com.almasb.fxgl.audio.impl.DesktopAndMobileAudioLoader.loadAudio(DesktopAndMobileAudioLoader.kt:37) at com.almasb.fxgl.audio.AudioPlayer.loadAudio(AudioPlayer.kt:193) at com.almasb.fxgl.app.services.SoundAssetLoader.load(FXGLAssetLoaderService.kt:681) at com.almasb.fxgl.app.services.SoundAssetLoader.load(FXGLAssetLoaderService.kt:677) at com.almasb.fxgl.app.services.AssetLoader.load(FXGLAssetLoaderService.kt:625) at com.almasb.fxgl.app.services.FXGLAssetLoaderService.load(FXGLAssetLoaderService.kt:530) at com.almasb.fxgl.app.services.FXGLAssetLoaderService.load(FXGLAssetLoaderService.kt:507) at com.almasb.fxgl.app.services.FXGLAssetLoaderService.load(FXGLAssetLoaderService.kt:496) at com.almasb.fxgl.app.services.FXGLAssetLoaderService.loadSound(FXGLAssetLoaderService.kt:196) at gildedsols.sound.SoundEffectManager.loadSoundEffectMap(SoundEffectManager.java:45) at gildedsols.sound.SoundEffectManager.run(SoundEffectManager.java:14) at java.base/java.lang.Thread.run(Thread.java:833)

dcejvan
@dcejvan
Would someone be able to explain what a Point2D is? Is it a directional vector or a position? little lost
Almas Baimagambetov
@AlmasB
@nbulgarides42 Hi, all FXGL timers are executed on the JavaFX thread and driven by the engine tick. If you have a long-running task, use an IOTask<*> and run it via FXGL.getTaskService().run(task) (or something like this, don't remember the API). When constructing the task IOTask.of(...) you can also set up callbacks to be run from a background thread or from the JavaFX thread, making the communication more streamlined.
@dcejvan Hi, there are a number of examples for animationBuilder() in fxgl-samples for reference. Typically, it's
animationBuilder(). provide configuration that is applicable for general animations, e.g. duration, number of repeats, etc. 
 then .translate/scale/rotate/animate, etc. (entity / view). then provide configuration that is specific to the animation
Almas Baimagambetov
@AlmasB
@nbulgarides42 FXGL does not do anything cross-platform itself. All calls are delegated to JavaFX in this case. Make sure you have javafx mac runtime libraries on the classpath. If you are building from a mac dev machine, shouldn't be an issue. However, if you build on a different platform (e.g. win), you will need to explicitly add all javafx runtime libs for the target platform (e.g. mac)
@dcejvan Point2D is not an FXGL class, it is from JavaFX. The way JavaFX defines it is both a directional vector and a position since from the data structure perspective, there is no difference (they both have the x and y values), even though their mathematical definitions are distinct.
nbulgarides42
@nbulgarides42
Hi @AlmasB, thank you for your answers, I appreciate your time. I've been asking you questions probably over a year now now but haven't really shown what I've been working on, if you are curious this is a three minute video showing what I'm making. It's a chess-based fantasy game called Gilded Sols https://www.youtube.com/watch?v=IRjuBLkDfOs&t=2s
Fury
@FuryCode-bit
Hello everyone, i started working with FXGL at the start of the week and now i'm trying to make a custom main menu. Is it possible to loop a video in the menu background? if yes, what is the best way to do it?
nbulgarides42
@nbulgarides42
Hi @Almas, I have a minimum reproducible example for the TCP server / client not working. The client and server seem to connect as I do not get a connect exception, however the following coce produces no output. I copied the code from the networking example and added a test message to see if I could get it to work. Could you verify it on your end and see if I did anything incorrectly below?
    private void serverTest(){

        var server = FXGL.getNetService().newTCPServer(42425);
        server.setOnConnected(connection -> {
            connection.addMessageHandlerFX((conn, message) -> {

            });
        });
        server.startAsync();

        var client = FXGL.getNetService().newTCPClient("23.119.210.170", 42425);
        client.setOnConnected(connection -> {
            connection.addMessageHandlerFX((conn, message) -> {
                displaySentMessage(message);
            });
        });

        client.connectAsync();
        var data = new Bundle("Stringtest");
        data.put("key", "Test message sent");
        server.broadcast(data);
    }

    private void displaySentMessage(Bundle message) {

        String messageText = message.get("key");
        System.out.println(message.getName());
        System.out.println(messageText);

    }
Almas Baimagambetov
@AlmasB
@nbulgarides42 Looks pretty awesome, thanks for sharing. The font reminded me of Arx Fatalis...
@FuryCode-bit Hi, JavaFX MediaPlayer supports looping, there should a few examples online on how to use it. The wiki page on customizing menus can then be helpful in putting it all together: https://github.com/AlmasB/FXGL/wiki/Customizing-Menus-%28FXGL-11%29
Almas Baimagambetov
@AlmasB
@nbulgarides42 Here's a minimal runnable example based on what you provided:
import com.almasb.fxgl.app.GameApplication;
import com.almasb.fxgl.app.GameSettings;
import com.almasb.fxgl.core.serialization.Bundle;
import com.almasb.fxgl.dsl.FXGL;
import javafx.scene.input.KeyCode;
import javafx.util.Duration;

import static com.almasb.fxgl.dsl.FXGL.*;

public class BasicTCPSample extends GameApplication {
    @Override
    protected void initSettings(GameSettings settings) { }

    @Override
    protected void initInput() {
        onKeyDown(KeyCode.Q, () -> {
            var server = FXGL.getNetService().newTCPServer(55555);
            server.setOnConnected(connection -> {

                runOnce(() -> {
                    var data = new Bundle("Stringtest");
                    data.put("key", "Test message sent");

                    server.broadcast(data);
                }, Duration.seconds(2));
            });

            server.startAsync();
        });

        onKeyDown(KeyCode.E, () -> {
            var client = FXGL.getNetService().newTCPClient("localhost", 55555);
            client.setOnConnected(connection -> {
                connection.addMessageHandlerFX((conn, message) -> {
                    displaySentMessage(message);
                });
            });

            client.connectAsync();
        });
    }

    private void displaySentMessage(Bundle message) {
        String messageText = message.get("key");
        System.out.println(message.getName());
        System.out.println(messageText);
    }

    public static void main(String[] args) {
        launch(args);
    }
}
Works fine.
  1. Press Q and give it some time for the server to start
  2. Press E to connect the client
  3. In ~2 seconds, you should see your message