Expo-pixi在App更高状态下保存舞台孩子并检索

时间:2019-07-10 20:21:10

标签: react-native expo

我正在尝试解决我的问题的另一种方法: 问题是:我用背景图像渲染了一个Sketch组件,并在其上进行草绘

onReady = async () => {
        const { layoutWidth, layoutHeight, points } = this.state;
        this.sketch.graphics = new PIXI.Graphics();
        const linesStored = this.props.screenProps.getSketchLines();

        if (this.sketch.stage) {

            if (layoutWidth && layoutHeight) {
                const background = await PIXI.Sprite.fromExpoAsync(this.props.image);
                background.width = layoutWidth * scaleR;
                background.height = layoutHeight * scaleR;

                this.sketch.stage.addChild(background);
                this.sketch.renderer._update();
            }

            if (linesStored) {
                for(let i = 0; i < linesStored.length; i++) {
                    this.sketch.stage.addChild(linesStored[i])
                    this.sketch.renderer._update();
                }
            }
        }
    };

此lineStored变量返回我保存在onChange上的数据:

onChangeAsync = async (param) => {
        const { uri } = await this.sketch.takeSnapshotAsync();

        this.setState({
            image: { uri },
            showSketch: false,
        });

        if (this.sketch.stage.children.length > 0) {
            this.props.screenProps.storeSketchOnState(this.sketch.stage.children);
        }

        this.props.callBackOnChange({
            image: uri,
            changeAction: this.state.onChangeAction,
            startSketch: this.startSketch,
            undoSketch: this.undoSketch,
        });
    };

storeSketchOnState保存this.sketch.stage.children;因此,当我更改屏幕并回到屏幕上以渲染我的Sketch组件时,我可以从App.js状态中获取sketch.stage.children并将其应用于Sketch组件以保留我之前所做的草图。

我正在尝试像这样应用检索到的数据

if (linesStored) {
                for(let i = 0; i < linesStored.length; i++) {
                    this.sketch.stage.addChild(linesStored[i])
                    this.sketch.renderer._update();
                }
            }
```

but it is not working =(

0 个答案:

没有答案