Socket
Book a DemoInstallSign in
Socket

react-spriter

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-spriter

ReactSpriter is a React component that allows you to create animated sprites by providing a convenient interface

Source
npmnpm
Version
0.0.2
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

This package is a work in progress!

npm version workflow cypress

React Spriter

ReactSpriter is a React component that allows you to create animated sprites using styled-components. It simplifies the process of animating sprites by providing a convenient interface to define sprite properties and animations.

DEMOS: https://react-spriter.callumeddisford.co.uk/

Features

  • Pause and play sprite
  • Change sprite layer

Installation

To use ReactSpriter in your React project, you can install it via npm or yarn:

npm install react-spriter

or

yarn add react-spriter

Usage

  • Import ReactSpriter into your component:
import ReactSpriter from "react-spriter";
  • Use ReactSpriter in your component's render method:
class MyComponent extends React.Component {
  render() {
    return (
      <ReactSpriter
        sprite={sprite}
        frameWidth={frameWidth}
        frameHeight={frameHeight}
        spriteWidth={spriteWidth}
        duration={animationDuration}
        isInfinite={isInfinite}
        shouldAnimate={shouldAnimate}
        layer={layer}
      />
    );
  }
}

Props

FieldTypeDescription
spritestringThe URL of the sprite image.
frameWidthnumberThe width of each frame in the sprite.
frameHeightnumberThe height of each frame in the sprite.
spriteWidthnumberThe total width of the sprite image.
animationDurationnumberThe duration of the animation in milliseconds.
isInfinitebooleanWhether the animation should loop infinitely.
shouldAnimateboolean(optional) Whether the animation should start automatically. Defaults to true.
layernumber(optional) The layer of the sprite animation. If multiple sprites are layered on top of each other, this value determines the order of rendering.

Examples

Here's an example of how you can use ReactSpriter to animate a sprite, in this example each frame width is 64 and the total sprite image width is 512 this indicates there are 8 frames to animate over:

import React from "react";
import ReactSpriter from "react-spriter";
import sprite from "path/to/sprite.png";

const MyComponent = () => {
  const frameWidth = 64;
  const frameHeight = 64;
  const spriteWidth = 512;
  const animationDuration = 1000;
  const isInfinite = true;
  const shouldAnimate = true;
  const layer = 0;

  return (
    <ReactSpriter
      sprite={sprite}
      frameWidth={frameWidth}
      frameHeight={frameHeight}
      spriteWidth={spriteWidth}
      duration={animationDuration}
      isInfinite={isInfinite}
      shouldAnimate={shouldAnimate}
      layer={layer}
    />
  );
};

export default MyComponent;

Please check out the src/examples directory for more

Local development

To start storybook locally:

  npm install
  npm run storybook

Keywords

react

FAQs

Package last updated on 21 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts