npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kaizer433/react-native-spritesheet

v0.1.3

Published

React Native SpriteSheet

Downloads

26

Readme

Sprite Component Library

Description

This library provides Sprite and AnimatedSprite components for React Native applications, utilizing react-native-reanimated and expo-image for smooth and efficient sprite animations. It's designed to be user-friendly and performant (60FPS), making it ideal for various applications like games and dynamic UIs.

Installation

To use the components in your project, ensure you have React Native set up. Install the library via npm:

npm install @kaizer433/react-native-spritesheet

Or via yarn:

yarn add @kaizer433/react-native-spritesheet

Usage

Sprite Component

Import the Sprite component from the library and use it in your React Native app:

import { Sprite } from '@kaizer433/react-native-spritesheet';

// Your component
function MyComponent() {
  return (
    <Sprite
      source={require('./path-to-your-spritesheet.png')}
      width={200}
      height={200}
      spriteSheetWidth={4420}
      spriteSheetHeight={130}
      frames={yourFrameData}
    />
  );
}

AnimatedSprite Component

Import the AnimatedSprite component for more complex animations:

import { AnimatedSprite } from '@kaizer433/react-native-spritesheet';

function MyAnimatedComponent() {
  return (
    <AnimatedSprite
      source={require('../assets/spritesheet/sprite/spritesheet.png')}
      spriteSheetWidth={4420}
      spriteSheetHeight={130}
      width={250}
      height={250}
      frames={SpritSheetJSON?.frames ?? []}
      defaultAnimationName="IDLE"
      animations={{
        IDLE: [10, 11, 12, 13, 14, 15, 16],
        ATTACK: [0, 1, 2, 3, 4, 5, 6],
        JUMP: [17, 18, 19, 20, 21, 22, 23, 24, 25],
        RUN: [27, 28, 29, 30, 31, 32, 33, 34],
        DIE: [7, 8, 9],
      }}
      inLoop={true}
      autoPlay={true}
    />
  );
}

Props

Sprite Component

  • source (ImageSourcePropType): The source of the sprite sheet image.
  • width (number): The width of a single frame in the sprite sheet.
  • height (number): The height of a single frame in the sprite sheet.
  • spriteSheetWidth (number): The total width of the sprite sheet.
  • spriteSheetHeight (number): The total height of the sprite sheet.
  • frames (Frame[]): An array of frame data, where each frame has a filename, x, y, w, and h.

AnimatedSprite Component

  • Inherits all props from the Sprite component.
  • defaultAnimationName (string): The name of the default animation to play.
  • animations (Record<string, number[]>): Object mapping animation names to frame indices.
  • inLoop (boolean): Whether the animation should loop.
  • autoPlay (boolean): Whether the animation should start automatically.
  • frameRate (number): Speed at which the animation frames are displayed.

Methods

Sprite Component

  • setCurrentFrameIndex(frameIndex: number): Sets the current frame to be displayed based on the frame index.

AnimatedSprite Component

  • startAnimation(animationName: string, loop?: boolean, frameRate?: number): Starts the animation with the given name. loop determines if the animation should loop.
  • getCurrentAnimationName(): Returns the name of the current animation.

Example

For example check this expo project


## Contributing

Contributions to the library are welcome. Please read the contributing guidelines before submitting your pull request.

## License

This library is licensed under the MIT License.