首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在应用程序运行时不调用本机和世博- onContextCreate函数

在应用程序运行时不调用本机和世博- onContextCreate函数
EN

Stack Overflow用户
提问于 2022-01-20 17:10:26
回答 1查看 56关注 0票数 0

我不知道为什么,在调试器-ui中也没有显示错误。我只看到白色屏幕在我的iphone没有错误。我还在console.log函数中添加了一个onContextCreate,没有消息,所以这意味着onContextCreate函数没有触发,这是我的代码。任何帮助都是非常有用的。

代码语言:javascript
运行
复制
import { View as GraphicsView } from 'expo-graphics';
import ExpoTHREE, { THREE } from 'expo-three';
import React from 'react';

export default class App extends React.Component {
  UNSAFE_componentWillMount() {
    THREE.suppressExpoWarnings();
  }

  render() {
    // Create an `ExpoGraphics.View` covering the whole screen, tell it to call our
    // `onContextCreate` function once it's initialized.
    return (
      <GraphicsView
        style={{backgroundColor: 'yellow'}}
        onContextCreate={this.onContextCreate}
        onRender={this.onRender}
      />
    );
  }

  // This is called by the `ExpoGraphics.View` once it's initialized
  onContextCreate = async ({
    gl,
    canvas,
    width,
    height,
    scale: pixelRatio,
  }) => {

    console.log('onContextCreate ran...');

    this.renderer = new ExpoTHREE.Renderer({ gl, pixelRatio, width, height });
    this.renderer.setClearColor(0xffffff)
    this.scene = new THREE.Scene();
    this.camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000);
    this.camera.position.z = 5;
    const geometry = new THREE.BoxGeometry(1, 1, 1);

    const material = new THREE.MeshPhongMaterial({
      color: 0xff0000,
    });
    
    this.cube = new THREE.Mesh(geometry, material);
    this.scene.add(this.cube);

    this.scene.add(new THREE.AmbientLight(0x404040));

    const light = new THREE.DirectionalLight(0xffffff, 0.5);
    light.position.set(3, 3, 3);
    this.scene.add(light);
  };

  onRender = delta => {
    this.cube.rotation.x += 3.5 * delta;
    this.cube.rotation.y += 2 * delta;
    this.renderer.render(this.scene, this.camera);

  };
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-20 19:05:53

我意识到当我在世博会上关闭远程调试器时,我的代码还在工作。这就是为什么发生了我不知道。这是好的,其他人解释它,但它的工作,当我关闭远程调试在世博会.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70790495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档