GithubHelp home page GithubHelp logo

adhbh / rn-sprite Goto Github PK

View Code? Open in Web Editor NEW
74.0 3.0 9.0 9.21 MB

rn-sprite is a react native component for creating animations from spritesheets

Home Page: https://www.npmjs.com/package/rn-sprite

JavaScript 100.00%

rn-sprite's Introduction

rn-sprite

rn-sprite is a react native component for creating animations from spritesheets for IOS and Android devices

...Spritesheets? ...Animations?

A sprite is a single graphic image that is incorporated into a larger scene so that it appears to be part of the scene. When you put many sprites into a single image, you get a spritesheet like this and this. The process of changing images in quick succession to give the illusion of movement is called animation.

Code:

<Sprite
	sequence={[ 
			0.04, 
			0.125, 0.20815, 0.2913, 0.37445, 0.4576, 
			0.54075, 0.6239, 0.70705, 0.7902, 0.87335, 0.9565,
			0.04,
	]}
	move="vertical"
	loop
	fps={10}
	isPlaying
	source="https://github.com/adhbh/rn-sprite/raw/master/vertical.jpg"
	width={windowWidth}
	height={windowHeight / 2}
	onTouchStart={() => true}
	onTouchMove={() => true}
	onTouchEnd={() => true}
/>
  • Depends on gl-react-native
  • Works on IOS and Android
  • Supports horizontal, vertical and grid spritesheets
  • Play/Pause support
  • Configurable animation speed
  • Touch responsive

props

prop type description required
source string Url of spritesheet image yes
sequence array Array of numbers between 0 and 1 that define the sequence of animation, or, in the case of a sprite grid, an array of pairs of numbers between 0 and 1 yes
loop boolean Repeat the animation when it completes (Default: true) no
fps integer Frames per second (Default: 2) no
isPlaying boolean Play/Pause the animation (Default: true) no
move string For horizontal or vertical spritesheets (Default: horizontal) no
onTouchStart function Function which is called when sprite is touched no
onTouchMove function Function which is called while the user touches and moves the finger on the sprite no
onTouchEnd function Function which is called when touch event gets completed no

Usage

  • Animations in mobile games
  • Replacement for gifs
  • 360-View

Installation

  • Setup RNGLPackage by following this guide for Android and IOS
  • npm install --save rn-sprite

Todo

  • Configurable repeat count for animation
  • Rewind support
  • Got some more ideas? Feel free to raise a PR

License

MIT

rn-sprite's People

Contributors

adhbh avatar queenvictoria avatar deadcoder0904 avatar

Stargazers

Tomasz Kania-Orzeł avatar 周杨 avatar Spencer Gray avatar  avatar Trevor Casey avatar Harsh Sharma avatar Aditya avatar Mert Cankat avatar Jon Gunnison avatar vsCoder avatar Indrajith Bandara avatar Charles-Antoine Fournel avatar alwayrun avatar ilker ALTIN avatar sunim avatar  avatar Kasper Lorentzen avatar 니콜라스 avatar Jack Kavanagh avatar Hunter MW avatar Reginald Johnson avatar Premprakash singh avatar Vincenzo Ciaccio avatar Lucas Bento avatar Juwan Wheatley avatar Jason Brown avatar  avatar Robert Khayat avatar littleyvan avatar Alexandre Nicastro avatar Yaşar İÇLİ avatar Ryan Allen avatar Jalal azimi avatar Khalid O. Lamptey avatar Kevin Hermawan avatar June Domingo avatar Klaus avatar Wanda Ichsanul Isra avatar Sonny Lazuardi avatar Jonathan Younger avatar Anjali Sinha avatar liushaobo avatar Tom Chambers avatar  avatar Arsen Ghazaryan avatar Martin van Driel avatar Hein Rutjes avatar William Falk-Wallace avatar Alex Lemanski avatar Fabio Dias Rollo avatar Don Ebben avatar Chan Long Sang avatar Shivam Sinha avatar Jackie Wu avatar Matt Votsikas McLean avatar Daniel Schmidt avatar Dante Cervantes avatar waleedarshad avatar Ramana Sundararaman avatar Erkan Sen avatar Jacob Lowe avatar Yamir avatar Jose Padilla avatar Chethan N avatar Anurag Dadheech avatar Neophy Bishnoi avatar Drapich Piotr avatar  avatar undefined avatar Jeff Chacko avatar swathy subhash avatar Sagar Khatri avatar Bryan Eaton avatar Justin Foss avatar

Watchers

James Cloos avatar  avatar  avatar

rn-sprite's Issues

Is this project still works?

Hi adhbh, i wan to try this repo, but I can't make it works, it loads the jpg your provided but cannot show the image, wondering is this repo still works? and also about the speed in iOS and Android, can the sprite is playing smoothly while click/scrolling other UI e.g.: list view, buttons?

How to update current frame?

Hi there. Thank you for the project!

I am trying to use onTouchMove to update the frame number of the sprite. Currently I've got something like this but I'm a bit lost as to how to bind to the frame number inside the library. Any tips?

        <Sprite
          sequence = { sequence }
          move = { move }
          rows = { rows }
          cols = { columns }
          loop = { true }
          fps = { 15 }
          current = { this.state.current }            // <---
          isPlaying = { false }
          source = { source }
          width = { 360 }
          height = { 668 }
          onTouchStart = { () => {
            this.setState({message: "onTouchStart"})
            return true;
          } }
          onTouchMove = { (evt) => {                    // <---
            // X and Y are relative to the top left
            let x = evt.nativeEvent.locationX;
            let y = evt.nativeEvent.locationY;
            let _x = x/360*100;
            let _y = y/668*100;
            this.setState({position: `x: ${Math.round(_x)}% y: ${Math.round(_y)}%`});
            this.setState({message:JSON.stringify(Object.keys(evt))})
            this.setState({current: 0})
          } }
          onTouchEnd = { (evt) => true }
        />

Need Help! How to generate the sequence

Hello, I am new to react native and sprite sheet animation, I need a help for generating the sequence for a sprite sheet. Please tell me how to generate the sequence for a sprite sheet.

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.