2.0.1 • Published 7 years ago

rn-sprite v2.0.1

Weekly downloads
22
License
-
Repository
github
Last release
7 years ago

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 = { true }
  fps = { 10 }
  isPlaying = { true }
  source = { 'https://github.com/adhbh/rn-sprite/raw/master/vertical.jpg' }
  width = { windowWidth }
  height = { windowHeight/2 }
  onTouchStart = { () => true }
  onTouchMove = { () => true }
  onTouchEnd = { () => true } />

props

proptypedescriptionrequired
sourcestringUrl of spritesheet imageyes
sequencearrayArray 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 1yes
loopbooleanRepeat the animation when it completes (Default: true)no
fpsintegerFrames per second (Default: 2)no
isPlayingbooleanPlay/Pause the animation (Default: true)no
movestringFor horizontal or vertical spritesheets (Default: horizontal)no
onTouchStartfunctionFunction which is called when sprite is touchedno
onTouchMovefunctionFunction which is called while the user touches and moves the finger on the spriteno
onTouchEndfunctionFunction which is called when touch event gets completedno

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