RPGJS v4.1 Release Notes
Hello dear developers! We're excited to introduce the latest version of RPGJS, v4.1. This version comes with new features, and among them, some experimental capabilities to enhance your game development experience. Let's dive into the highlights:
1. Building GUI with React
You can now build your game's GUI using React. RPGJS v4.1 integrates React into its architecture, allowing you to seamlessly create interactive and dynamic user interfaces.
Example:
Here's a simple example to get you started:
import { RpgReactContext } from '@rpgjs/client/react';
import { useContext, useEffect, useState } from 'react';
export default function MyGUI() {
const { rpgCurrentPlayer } = useContext(RpgReactContext);
const [hp, setHp] = useState(0);
useEffect(() => {
const subscription = rpgCurrentPlayer.subscribe(({ object }) => {
setHp(object.hp);
});
return () => {
subscription.unsubscribe();
};
}, []);
return (
<div>
<h1>{hp}</h1>
</div>
);
}
Note: This React integration is an experimental feature. It's still in the development phase and might have some unexpected behaviors. As always, we appreciate your feedback and bug reports to make it stable in future versions.
For a comprehensive guide, please refer to our documentation: RPGJS GUI with React.
2. New Hooks in RpgEvent
class
In v4.1, we're introducing two hooks that will provide you with more control over events in the game world. These hooks are especially useful to determine when a player or another event is within a certain proximity.
onDetectInShape
This hook is triggered when a player or another event enters the shape attached to the current event.
onDetectInShape(player: RpgPlayer, shape: RpgShape) {
// Your custom code here
}
onDetectOutShape
Conversely, this hook is triggered when a player or another event leaves the shape attached to the current event.
onDetectOutShape(player: RpgPlayer, shape: RpgShape) {
// Your custom code here
}
Playground Example: https://playground.rpgjs.dev/move_to
Thank you for your continued support. We're eager to see the games and experiences you'll create with these new features. Stay tuned for more updates, and happy game developing!