Simple React Native Image Game 是 Lagging.How 我要优化吗?

Simple React Native Image Game is Lagging.How do i optimize?

我正在尝试使用 React Native 实现一个简单的 img 点击游戏以进行学习 purposes.I 我正在使用这个库 https://github.com/bberak/react-native-game-engine 游戏循环组件作为游戏循环。

我想要做的是在屏幕上以小半径渲染一些具有随机位置的 img,然后将其增加到一个值,在减小它之后最后从屏幕上删除 img(或在点击时) - 就像在本场比赛:http://mouseaccuracy.com/

import React, { Component } from "react";
import { AppRegistry, StyleSheet, Dimensions, View,ToastAndroid,TouchableOpacity,Image,Text } from "react-native";



    const { width: WIDTH, height: HEIGHT } = Dimensions.get("window");
    import { GameLoop } from "react-native-game-engine";
    import { Fonts } from '../utils/Fonts';
    import FastImage from 'react-native-fast-image'
    import * as Progress from 'react-native-progress';
    import SwordImage from "../assets/tapfight/sword.png";
    import ShieldImage from "../assets/tapfight/shield.png";


          this.renderSwordOrCircle(circle)
        )


            })




    )




    }


       }

     renderHealth = () =>{
    return(
      <View>
        <View style={{ alignItems:'center' ,position: "absolute", top: 0, left: 0}}>
        <Text style={{fontFamily:Fonts.MainFont,color:'white',fontSize:25}}>{this.playerHealth}</Text>
        <Progress.Bar color='red' progress={this.playerHealth/100} width={100} height={18} />

        </View>
        <View style={{ alignItems:'center',position: "absolute", top: 0, right: 0}}>
        <Text style={{fontFamily:Fonts.MainFont,color:'white',fontSize:25}}>{this.enemyHealth}</Text>
        <Progress.Bar  color='red' progress={this.enemyHealth/100} width={100} height={18} />
         <FastImage resizeMode="contain" style={{width:100,height:100}} source={require('../assets/tapfight/guard_2_head.png')}></FastImage>
        </View>

      </View>


    )



     }


      render() {
        if(this.state.fight==true){
          return (
            <View style={{flex:1,backgroundColor:'transparent'}} > 
             <GameLoop style={{flex:1}} onUpdate={this.updateCircle}> 
             {this.renderHealth()} 
             {this.renderCircles()}     
             </GameLoop>       
             </View>

          );

        }else{

    return(
      null
    )

        }

      }
    }

    const styles = StyleSheet.create({
      container: {
        flex: 1,
      }
    });

我正在做的是我每 600 毫秒在屏幕上生成图像并且播放器尝试点击 them.The 问题是当屏幕上有超过 2 个图像时 [=] 中 fps 下降 significantly.Tested 24=] 实际 device.I 在 updateCircle 函数结束时更新一次状态。 游戏循环是 updateCircle 组件

您的问题是您正在尝试为一个组件设置动画,该组件不是为制作动画而制作的

我不太了解 FastImage 组件,但我知道它的目的是预加载图像,而不是动画。

您应该使用 Animated.Image 作为图像,并使用 Animated.timing 来管理 Animated.Image

的动画