【问题标题】:Animation not working in ReactVR动画在 ReactVR 中不起作用
【发布时间】:2017-11-17 14:06:24
【问题描述】:

我似乎在某处遗漏了一件事,因为我在控制台中没有看到任何错误,但动画似乎没有运行,或者我的场景太重,以至于动画在模型实际加载之前运行。 ..我的代码中缺少什么?

import React from 'react';
import { asset, View, StyleSheet, Model, Animated } from 'react-vr';

const AnimatedModel = Animated.createAnimatedComponent(Model);

export default class Loral extends React.Component {
   constructor(props) {
     super(props);
    this.state = {
      satelliteTransX: new Animated.Value(3),
      satelliteRotY: -45,
    };
  }

  componentDidMount() {
     this.state.satelliteTransX.setValue(3);
     Animated.timing(
       this.state.satelliteTransX,
      {
        toValue: 10,
        duration: 1000,
        delay: 1000
      }
     ).start();
   }

   render() {
     return (
       <View>
         <AnimatedModel 
           source={{
             obj: asset('/Loral-1300Com-obj/Loral-1300Com-main.obj'),
             mtl: asset('/Loral-1300Com-obj/Loral-1300Com-main.mtl')
           }}
           style={{
                 transform: [
                {translate: [this.state.satelliteTransX, 0, -10]},
                { scale: 0.01 },
                { rotateX: 30},
                { rotateY: this.state.satelliteRotY }
             ]
           }} 
         />
      </View>
     );
  }
};

【问题讨论】:

    标签: reactjs react-360


    【解决方案1】:

    尝试按轴单独设置您的翻译,而不是这样:

     style={{
        transform: [
           {translate: [this.state.satelliteTransX, 0, -10]},
           { scale: 0.01 },
           { rotateX: 30},
           { rotateY: this.state.satelliteRotY }
        ]
     }} 
    

    试试这个

     style={{
        transform: [
           {translateX: this.state.satelliteTransX},
           {translateY: 0},
           {translateZ: -10},
           { scale: 0.01 },
           { rotateX: 30},
           { rotateY: this.state.satelliteRotY }
        ]
     }} 
    

    这应该对你有用。对于上面提到的数组中引用的所有动画属性,我都遇到了这个问题。

    【讨论】:

    • 不确定我是否遵循您的建议。我的平移 X 轴已经是独立的,并且我正在尝试设置动画的值。你能在我的代码中告诉我你推荐什么吗?
    • 抱歉 - 有点不清楚。更新了我的答案。
    猜你喜欢
    • 2013-02-18
    • 2012-08-06
    • 2015-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多