简体   繁体   English

如何使用a动画更改a帧中的文本?

[英]How do I change text in a-frame using a-animations?

For example, I have some text "Hello" floating about in the scene, on mousing over it I want the text to change to "Hi" 例如,场景中有一些文本“ Hello”,在鼠标悬停时,我希望文本更改为“ Hi”

Right now, when I try to use an animation, the text just disappears off, instead of changing. 现在,当我尝试使用动画时,文本只是消失而不是改变。 Any help? 有什么帮助吗? Thanks. 谢谢。

I would use the event-set component (download the dist and drop into your project), not the animation tag: 我将使用事件集组件 (下载dist并放入您的项目中),而不是使用animation标签:

<a-entity text="text: Hello" event-set="_event: mouseenter; text: Hi"></a-entity>

0.2.0 build: https://github.com/ngokevin/aframe-event-set-component/tree/v0.2.0/dist 0.2.0版本: https//github.com/ngokevin/aframe-event-set-component/tree/v0.2.0/dist

0.3.0 build https://github.com/ngokevin/aframe-event-set-component/tree/master/dist 0.3.0构建https://github.com/ngokevin/aframe-event-set-component/tree/master/dist

Here is an example using JavaScript to change text on mouseover. 这是一个使用JavaScript在鼠标悬停时更改文本的示例。

Ignoring the boilerplate used to wait for the scene to load, the code is: 忽略用于等待场景加载的样板,代码为:

var someText = document.querySelector('#someText');
someText.addEventListener('mouseenter', mouseenter);

function mouseenter () {
  someText.setAttribute('bmfont-text', 'text: Hi');
}

Where "someText" points to an entity with the bmfont-text component (though it would work for geometric text as well). 其中“ someText”指向具有bmfont-text组件的实体(尽管它也适用于几何文本 )。 This example uses Mayognaise's mouse cursor component but could easily be changed to a gaze-cursor. 本示例使用Mayognaise的鼠标光标组件,但可以轻松更改为凝视光标。

- --

Additionally, here is a CodePen demonstrating ngokevin's answer . 另外, 这是一个CodePen演示ngokevin的答案 I was going to post this as a comment to his answer, but I don't have enough reputation points... 我本来打算以此作为对他的回答的评论,但我的声誉得分不足...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM