B4J Library SimpleGameEngine

Informatix

Expert
Licensed User
Longtime User
This is not due to the library but to the demo. I didn't protect the particular case where you want to find the exit while being already at the exit. In this case, the algorithm returns Null for Waypoints and the demo code crashes because it cannot handle Null.
 

Informatix

Expert
Licensed User
Longtime User
Here's how to load assets with Wait For (requires B4J v5.5+):
B4X:
AM.Add(AssetType, UniqueName, Folder, FileName)
AM.Add(...)
AM.LoadAllAssets OR AM.LoadThisAsset(AssetType, UniqueName)
Wait For AM_Loaded
That may be useful in some cases as the Loaded event does not return details.
That does not prevent the Loading event sub from being called as usual before loading an asset. Note that there's no obvious interest to use Wait For for the Loading event, especially with numerous assets.
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
Maybe some users of this library are surprised by the lack of mouse events for the actors and groups of SGE, contrary to their counterpart in LibGdx. There's only a sgeInput class to detect all events at the SGE level. It's by design. You're invited to use another approach for the handling of mouse events.
Traditionally, you have a dispatching function in the library code that tries to find which object currently on screen is concerned by the mouse event, then raises the event for this object (with the risk of targeting the wrong object because rules may apply that are specific to your game). In SGE, you have to detect yourself the right object. For example, if you want to detect only visible groups, this code will get you all groups under the mouse position, orderer by Z-order (the topmost being the first):
B4X:
Sub SGE_MousePressed(EventData As MouseEvent)
    Dim MouseClick As sgePoint2D = SGE.Input.MouseToCanvas(EventData.X, EventData.Y)
    Dim ClickedList As List = SGE.Root.FindAtPos2(MouseClick, SGE.Root.FIND_ONLY_GROUPS, True)
    Dim ClickedGroup As sgeGroup
    If ClickedList.Size > 0 Then
        ClickedGroup = ClickedList.Get(0)
    End If
    If ClickedGroup.IsInitialized Then
        'There's a group found under the mouse. Your program can call the appropriate function to handle this event.
    ...
End Sub
Imagine that you want to prevent a great number of groups and actors from receiving events at a given time (because the player has not found yet the sword of light to slash monsters with furious mouse clicks, or because you want to display some kind of modal dialog, etc.), the usual approach is to add a restriction in the event handlers of all objects (something like "if not concerned then return"). Problem: it's hard to maintain in a complex project. You should consider that the event handler specific to actors or groups always receives a valid event and has to deal with. It means that all restrictions have to be handled by your dispatching code. For example:
B4X:
    ...
    If ClickedGroup.IsInitialized Then
        'There's a group found under the mouse. Your program can call the appropriate function to handle this event.
        If MyModalDialogIsDisplayed = True Then
            'My modal dialog has a button and, of course, the player is allowed to interact with it. Not with the other objects on screen.
            'The class that created the button and handles clicks on it is stored in the Tag property.
            if ClickedGroup.Tag is clsDialogButton then
                Dim Button As clsDialogButton = ClickedGroup.Tag
                Button.MousePressed(EventData)
            Else
                Return
            End if
        End if
        ...
    End if
End Sub
In the above example, you see that you don't have to write "If MyModalDialogIsDisplayed = True Then Return" everywhere, or to add an invisible object to block events like I saw in many apps. Moreover, all rules are in a single place. In my current game, I just had to add three lines of code in my dispatcher to avoid handling events when some animations are in progress, and only one line for the paused state ("If Paused Then Return", and exactly the same line in SGE_Update to freeze everything).
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
About the 9-patch support in v1.3:
A 9-patch PNG image used under Android has two areas: the scalable area (defined by the black lines at the top and left) and the content area (defined by the black lines at the bottom and right). The content area is not supported by SGE for now.
 

ilan

Expert
Licensed User
Longtime User
hi @Informatix, any chance SGE will support gamepads?

i saw that you mentioned already about a missing USB lib for b4j but sorry for my silly question.
if my keyboard that is connected via USB i can catch all button clicks why can't i do the same with a connected Joystick?
 

Informatix

Expert
Licensed User
Longtime User
I would really like to have a gamepad support in SGE, but there's no mean to read the gamepad data with JavaFX. A gamepad is not a keyboard nor a mouse; it has its own messages. Since nobody implemented the communication with the device in JavaFX, there's no event, no listener, nothing. And I don't want to write an USB library. Not enough time.
 

ilan

Expert
Licensed User
Longtime User
implemented the communication with the device in JavaFX, there's no event, no listener, nothing

oh ok i understand.
so if there would be a USB lib it will be able to listen to any attached Hardware?

i see lot of emulators or games where you can configure your controls to use any button. it also works with gamepads and i would like to implement something like this in my b4j game. i just bought me a joystick for tests and i tried it with "MyNes" (its a NES emulator) and it works great but i guess i will need to wait until a java genius will wrap a b4j lib for us
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…