How to load a new scene in A-Frame?

后端 未结 1 1639
时光取名叫无心
时光取名叫无心 2021-01-16 00:13

I am using A-Frame (JavaScript library). I would like to load a new scene when user clicks into a certain component in the current scene. How can I achieve this?

1条回答
  •  悲&欢浪女
    2021-01-16 01:05

    Check out the A-Frame Template Component. Notably the Swapping Example.

    You can either define your separate scenes within script tags or within separate files. Here is an example with script tag templating:

    
      
      
        
        
      
    
      
    
    

    Then when you want to change your scene, change the src:

    
    

    Here is an example component to programmatically change template src on interval: https://github.com/ngokevin/kframe/blob/master/components/template/examples/swapping/components/template-looper.js

    Mainly it will be el.setAttribute('template', 'src', '#sphere');

    For other components that could assist changing the src:

    • Event Set Component can help listen to your mouseenter and change the src in response.
    • The template component also comes with template-set component that will change the template on an event.

    0 讨论(0)
提交回复
热议问题