Lili's Game Engine

SolidJS Plugin Documentation

Description:
Create dynamic GUIs using interactive HTML

Plugin Source CodeView SolidJS's WebsiteUsage Demos:
  • solid-plugin-demo (source),
  • level-loader-demo (source),
  • topdown (source),
  • sidescroller (source),
  • spike-vs-space (source)

The SolidJS renderer is very straightforward if you know how to use SolidJS. First we create a signal that will be used to define where the Solid contents will be outputted inside your SolidJS application. First provide the setter method to the plugin initialization, and then the getter of that method is used to define where all of the SolidJS contents will be outputted in the DOM. In the topdown demo we can see what that looks like in our main game component:

export default function Game() {
    const [solidGameContents, setSolidGameContents] = createSignal(null)
	onMount(async ()=>{
        if (isServer) return
		const entities = EntityList([])
		const renderSettings = RenderSettings({canvas})
		renderSettings.solidSetter = setSolidGameContents
		const solidRenderer = createSolidRenderer(entities, renderSettings)
	})
    return (<div class="game-container">
        <canvas ref={canvas}/>
        {solidGameContents()}
    </div>)
}

Any Entity can render a component to the screen by setting that component as it’s .solid property. That Entity will be passed to the component automatically through the {entity} prop. Since we’ve done the above SolidJS plugin setup all we need to do now is this:

const touchControls = entities.addChild({solid: TouchControls})

The TouchControls component can modify it’s {entity} prop to change the values of the touchControls Entity, and we can read and listen to changes in those values. To make those touch controls affect the player movement for example we can define a custom plugin that changes the player’s matter momentum based on the values of the touchControls Entity each tick:

const playerControlPlugin = {
	tick: () => {
		if (!player.matterBody) return
		Body.setVelocity(player.matterBody, {x: touchControls.xDirection * walkForce, y: touchControls.yDirection * walkForce})
	}
}
// Also we will add it to our gameCore plugin list below

More about SolidJS

To learn how to use SolidJS please see their website.

AI Usage DisclosureSource Code (star this?)