ibGoge Posted October 8, 2018 Share Posted October 8, 2018 Hi, When loading a new level I dispose the old scene and create a new one. My input system observes a new scene was created, unsubscribes itself from the old one, and subscribes to the new scene. The mouse events continue on as normal from the new scene but the keyboard events stop. If I remove focus from the canvas, focus on another html element, and then return to the canvas, I begin to receive keyboard events again. The 'keyboard info' console log stops when the new scene is attached to. Am I missing something else that needs to be done to recapture the keyboard with a new scene? Thanks! attachScene(scene) { this.clearStates() this.scene = scene this.onKeyboardObserver = scene.onKeyboardObservable.add((info) => { console.log('keyboard info', info); this.handleBabylonOnKeyboard(info) }) this.onMouseObserver = scene.onPointerObservable.add(this.handleBabylonOnPointer, BABYLON.PointerEventTypes.POINTERDOWN | BABYLON.PointerEventTypes.POINTERUP | BABYLON.PointerEventTypes.POINTERMOVE); } detachSecne(scene) { this.clearStates() if (this.scene == undefined) { return } this.scene = undefined scene.onKeyboardObservable.remove(this.onKeyboardObserver) scene.onPointerObservable.remove(this.onMouseObserver) this.onKeyboardObserver = undefined this.onMouseObserver = undefined } createScene() { if (this.currentScene) { this.currentScene.dispose(); } if (this._camera) { this._camera.dispose(); this._camera = undefined; } // remove watched game objects Object.values(this.objects).forEach(object => this.removeObject(object)) // reset material cache this.cachedMaterial = {} // create new scene let engine = this.engine this.currentScene = new BABYLON.Scene(engine) this.currentScene$.next(this.currentScene); // create default min light level var light = new BABYLON.HemisphericLight("HemiLight", new BABYLON.Vector3(0, 1, 0), this.currentScene); light.color = new BABYLON.Color3(0,0,0) light.intensity = 2 * 0.1 window.ambientLight = light } Quote Link to comment Share on other sites More sharing options...
JohnK Posted October 9, 2018 Share Posted October 9, 2018 Have you tried setting the focus on the canvas with code? The canvas element is not focusable by default. You need to set a tab index for the canvas <canvas tabindex=0 ></canvas> trevordev and GameMonetize 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.