Hi, I'm trying to use the spine-player in a react-native app using Expo. I have this code
import React, { useRef } from "react";
import { ExpoWebGLRenderingContext, GLView } from 'expo-gl';
import spine from '@esotericsoftware/spine-player';
const Character = () => {
const glViewRef = useRef<GLView>(null);
const onContextCreate = async (gl: ExpoWebGLRenderingContext) => {
const myString = glViewRef.current!.nativeRef!.toString();
new spine.SpinePlayer(myString, {
jsonUrl: "assets/spine/spineboy-pro.json",
atlasUrl: "assets/spine/spineboy-pro.atlas",
animation: "walk",
showControls: false,
premultipliedAlpha: true,
backgroundColor: "#cccccc",
alpha: true,
preserveDrawingBuffer: true,
defaultMix: 1,
controlBones: ["root"],
viewport: {
debugRender: true,
},
});
};
return (
<GLView
style={{ flex: 1 }}
onContextCreate={onContextCreate}
ref={glViewRef}
/>
);
};
export default Character;
It seems like myString is undefined. Since the SpinePlayer requires a string or a HTMLElement, I can't figure out how to make this work. Is it possible? If so, how?
Thank you
If your UI toolkit is not actually HTML, then SpinePlayer is not going to work. It looks like you can use a WebView to render HTML, so you could try putting the SpinePlayer into a WebView.
However, I do need to customise the character.. like to add a hat. I do believe I can use OpenGL, so I'll try that! I'll come back here when I have a solution to offer.. or ran out of ideas! Thank you!