Giter Site home page Giter Site logo

hau-hau / react-native-spine-player Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 124 KB

Demonstration of Spine2D integration within React Native, rendered on Skia.

License: MIT License

JavaScript 0.16% CMake 2.01% C++ 29.61% Java 58.02% TypeScript 9.70% Ruby 0.50%

react-native-spine-player's Introduction

React-Native-Spine-Player

This repository contains a library that integrates Spine2D with React Native, using Skia for rendering.

It's important to know that this isn't aiming to be the ultimate Spine2D solution for React Native. Instead, it's a demo showing how these technologies can work together. So, don't expect that this implementation will cover every possible use case.

Still, it does work. It can handle multiple animations at a decent speed of 30 FPS. Just remember, performance might vary based on things like how big your assets are and the size of the canvas used for the animation.

Please be advised that this project is experimental in nature. Due to lack of time, I'm not able to provide support for any bugs or usage issues that may arise. However, feel free to utilize the code as you see fit for your own purposes.

Integration Steps

  1. Copy the 'react-native-spine-player' directory into your project's directory.
  2. Navigate to the 'react-native-spine-player' directory and execute npm install.
  3. Within the 'react-native-spine-player' directory, run npm run init.
  4. Within the 'react-native-spine-player' directory, run npm run build.
  5. In your 'package.json', under 'dependencies', include "react-native-spine-player": "file:react-native-spine-player".
  6. Use component
import { useRef, useState } from "react";
import { readAsStringAsync } from "expo-file-system";
import { SpinePlayerView, SpinePlayerEventCommands } from "react-native-spine-player";

const FooComponent = () => {
  const spinePlayerViewRef = useRef<SpinePlayerEventCommands>(null);
  const [atlas, setAtlas] = useState<string | null>(null);
  resolveAsync(require("/assets/spine/raptor.atlas")).then((asset) => {
    readAsStringAsync(asset.localUri!).then((text) => {
      setAtlas(text ?? null);
    });
  });

    return (
        <SpinePlayerView
            ref={spinePlayerViewRef}
            
            // width and height have to be provided!
            style={{ width: 200, height: 200, backgroundColor: "green" }}
            x={100}
            y={200}
            image={require("/assets/spine/raptor.png")}
            atlasData={atlas ?? ""}
            skeletonData={JSON.stringify(require("/assets/spine/raptor.json"))}

            // raptor animations: "walk", "jump", "roar", "gun-holster", "gun-grab"
            animationNames={["jump"]}
            defaultMix={0.3}
            mixes={[{ from: "walk", to: "jump", value: 0.7 }]}
            loopAnimation
            autoPlay
            playbackSpeed={1}
            onSpineEvent={(e) => console.log(JSON.stringify(e.nativeEvent))}
          />
    )
};

Functionalities Currently Implemented

  • Support for Android
  • Compatibility with Spine 4.2
  • Loading capabilities based on .json and .atlas files
  • Simultaneous playback of multiple animations
  • Support for animation blends (mixes)
  • Control over playback speed
  • Autoplay feature
  • Seamless looping functionality
  • Event handling
  • Ref based commands for Play, Stop, and Reset operations
  • Spine 4.2 Physics (not extensively tested)

react-native-spine-player's People

Contributors

hau-hau avatar

Stargazers

Adam Gerthel avatar

Watchers

 avatar

Forkers

canh7antt8a

react-native-spine-player's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.