Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to play multiple sprite sheet one after another? #9

Open
NainalChauhan opened this issue May 24, 2019 · 3 comments
Open

How to play multiple sprite sheet one after another? #9

NainalChauhan opened this issue May 24, 2019 · 3 comments

Comments

@NainalChauhan
Copy link

I want to play different sprite sheet when first sprite animation finishes. I have tried setting source as a state but it doesn't work. Is there any other way to do this.

@mileung
Copy link
Owner

mileung commented May 24, 2019

Use multiple SpriteSheet components and lay them on top of each other with absolute positioning.

@elisechant
Copy link
Contributor

elisechant commented Apr 24, 2020

@NainalChauhan yes, the code would look something like this:

import React, { useRef, useState } from 'react';
import { View, Button } from 'react-native';
import SpriteSheet from "rn-sprite-sheet";

const MyView = () => {
  const elSlider1 = useRef(null);
  const elSlider2 = useRef(null);
  const [slider1IsVisible, setSlider1IsVisible] = useState(true);
  return (
    <View>
      <View style={{position:'relative'}}>
        <View style={{position:'absolute', opacity: slider1IsVisible ? 1 : 0}}>
          <SpriteSheet ref={elSlider1} source={Sprite1} animations={{anim1: []}} />
        </View>
        <View style={{position:'absolute'}}>
          <SpriteSheet ref={elSlider2} source={Sprite2} animations={{anim2: []}} />
        </View>
      </View>
      <Button onPress={() => {
        if (elSlider1.current) {
          elSlider1.current.play({ 
            type: 'anim1', 
            onFinish: () => {
              setSlider1IsVisible(false);
              elSlider2.current.play({type: 'anim2' });
            }
          });
        }
      }} title={'Play 1 then 2'} />
    </View>
  )
};

@JeffGuKang
Copy link

JeffGuKang commented Sep 8, 2020

Or you can recreate SpriteSheet instance at the specific timing to use useMemo.
It is simple and neat way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants