gzlock
V2EX  ›  问与答

用“跳一跳”也在用的 three.js 引擎做了个小场景在微信开发者工具中可以看到画面,但是用微信扫码预览却是黑屏,求解

  •  
  •   gzlock · Jan 1, 2018 · 4726 views
    This topic created in 3077 days ago, the information mentioned may be changed or developed.

    测试项目按照教程的来建立,App id 点击了箭头所指的小游戏,创建的模版小游戏 2D 打飞机在微信预览里可以玩的

    然后使用 Three.js ( r88 版本)来实现了一个简单的旋转正方体场景,在开发者工具中可以正常运行

    但是在微信中预览是黑屏

    扫码的微信运行 android 8.0 的系统上,WebGL 的支持程度方面应该不是问题。

    那么问题可能是出在 three.js 版本上?

    可以从 /t/419056 帖子中说到的跳一跳源码找出所使用的 three.js 的版本吗?

    我的 game.js 代码如下

    import './js/libs/weapp-adapter'
    import * as THREE from './js/libs/three'
    
    //weapp-adapter 会提供全局 canvas
    //let canvas = document.querySelector('canvas');
    //if (!canvas) {
    //	canvas = wx.createCanvas()
    //}*/
    
    const scene = new THREE.Scene()
    const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
    const renderer = new THREE.WebGLRenderer({canvas})
    renderer.setSize(window.innerWidth, window.innerHeight)
    const cube = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), new THREE.MeshBasicMaterial({color: 0x00ff00}))
    scene.add(cube)
    camera.position.z = 5
    
    function render() {
    	cube.rotation.x += 0.05
    	cube.rotation.y += 0.05
    	renderer.render(scene, camera)
    	window.requestAnimationFrame(render)
    }
    
    render()
    

    ps : 萌新水平有限,就不回答与本问题无关的问题了哈,请各位客官老爷见谅

    5 replies    2018-02-23 16:44:45 +08:00
    gzl0ck
        1
    gzl0ck  
       Jan 1, 2018
    沉了顶一下~
    gzlock
        2
    gzlock  
    OP
       Jan 1, 2018

    用开发者工具跑了一下跳一跳,也是 three 88 版本。
    这就排除了 three 版本的问题了 。
    那我就真不知道是什么导致了在微信中预览只有黑屏的问题了
    gzlock
        3
    gzlock  
    OP
       Jan 2, 2018 via Android
    应该是需要修改 three.js 适应微信小游戏,但是 three.js 代码量巨大,对于新手来说真的抓瞎
    gzl0ck
        4
    gzl0ck  
       Jan 2, 2018
    用跳一跳压缩过的代码对比了一下 three.js ,发现的确是有些不同的,但是 three.js 的代码量真的巨大,而且是精简过变量名的,没办法各处详细对比
    coffeSlider
        5
    coffeSlider  
       Feb 23, 2018
    找到解决方案了吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2646 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 11:50 · PVG 19:50 · LAX 04:50 · JFK 07:50
    ♥ Do have faith in what you're doing.