Change image of sky every few seconds with an animation

二次信任 提交于 2019-12-13 03:59:57

问题


I need change the image of sky every few seconds with an animation.

like this. But without the event click, in my case, i need the change of picture with time.

    <a-assets>
        <img id="water" src="./3D/letras/Agua.jpg"/>
        <img id="air" src="./3D/letras/Aire.jpg"/>
        <img id="horizont" src="./3D/letras/Horizonte.jpg"/>
        <img id="hector" src="./3D/letras/hecxtor.jpg"/>
    </a-assets>


回答1:


How about this.
You make two animations: a fade-in, and a fade-out:

<a-sky foo>
   <a-animation id="fadein-animation"></a-animation>
   <a-animation id="fadein-animation"></a-animation>
</a-sky>

The idea is to animate the opacity, and when the image is not visible, switch the source:

AFRAME.registerComponent("foo", {
  init: function() {
    var self = this.el
    var fadeInAnim = document.querySelector("#fadein-animation")
    var fadeOutAnim = document.querySelector("#fadeout-animation")
    var images = ["img1.jpg","img2.jpg"]
    var switchflip = 1
    fadeOutAnim.addEventListener("animationend", (e) => {
      self.setAttribute("material", "src", images[switchflip])
      switchflip = switchflip === 1 ? 0 : 1
      self.emit('fadein')
    })
    fadeInAnim.addEventListener("animationend", (e) => {
      self.emit('fadeout')
    })
 }
})

Working fiddle here.



来源:https://stackoverflow.com/questions/49743124/change-image-of-sky-every-few-seconds-with-an-animation

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