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();
}`
@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)?
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.
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();
}
}
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);
}
}
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));
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.
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)
atcom.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)
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.
animationBuilder()
in fxgl-samples for reference. Typically, it'sanimationBuilder(). 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
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);
}
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);
}
}