Expo-pixi Save stage children on App higher state and retrieve

旧街凉风 提交于 2019-12-11 05:54:15

问题


I'm trying another solution to my problem: The thing is: im rendering a Sketch component with a background image and sketching over it

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();
                }
            }
        }
    };

this lineStored variable is returning a data i've saved 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 saves this.sketch.stage.children; so when i change screen and back to the screen my Sketch component in being rendered, i can retrieve the sketch.stage.children from App.js state and apply to Sketch component to persist the sketching i was doing before

i'm trying to apply the retrieved data like this

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 =(

来源:https://stackoverflow.com/questions/56978080/expo-pixi-save-stage-children-on-app-higher-state-and-retrieve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!