@@ -11,7 +11,8 @@ order: 4
1111![ 360° ; Image Viewer] ( /images/docs/360-image-viewer.png )
1212
1313Let's go through an example building a scene using an
14- [ entity-component-system] [ ecs ] workflow. This guide will introduce three concepts:
14+ [ entity-component-system] [ ecs ] workflow. This guide will introduce three
15+ concepts:
1516
16171 . Using the standard [ components] [ components ] that ship with A-Frame.
17182 . Using third-party components from the ecosystem.
@@ -30,6 +31,8 @@ This is the starting point for our scene:
3031``` html
3132<a-scene >
3233 <a-assets >
34+ <audio id =" click-sound" src =" audio/click.ogg" ></audio >
35+
3336 <!-- Images. -->
3437 <img id =" city" src =" img/city.jpg" >
3538 <img id =" city-thumb" src =" img/thumb-city.png" >
@@ -48,9 +51,9 @@ This is the starting point for our scene:
4851 <!-- Camera + Cursor. -->
4952 <a-camera >
5053 <a-cursor id =" cursor" ></a-cursor >
51- <a-animation begin =" cursor- click" easing =" ease-in" attribute =" scale"
54+ <a-animation begin =" click" easing =" ease-in" attribute =" scale"
5255 fill =" backwards" from =" 0.1 0.1 0.1" to =" 1 1 1" dur =" 150" ></a-animation >
53- <a-animation begin =" cursor- fusing" easing =" ease-in" attribute =" scale"
56+ <a-animation begin =" fusing" easing =" ease-in" attribute =" scale"
5457 from =" 1 1 1" to =" 0.1 0.1 0.1" dur =" 1500" ></a-animation >
5558 </a-cursor >
5659 </a-camera >
@@ -95,13 +98,13 @@ defined in the asset management system.
9598Let's attach one more standard component, the [ sound component] [ sound ] . We want
9699to make it such that when we click (via gazing) on the link, it plays a click
97100sound. The syntax is the same as just before, but now we are using the sound
98- component's properties. We set ` on ` to ` cursor- click` so the sound is played on
99- click. And we set ` src ` to ` audio/ click.ogg ` , our path to a sound file:
101+ component's properties. We set ` on ` to ` click ` so the sound is played on click.
102+ And we set ` src ` to ` # click-sound ` , a selector to our ` <audio> ` element.
100103
101104``` html
102105<a-plane class =" link" height =" 1" width =" 1"
103106 material =" shader: flat; src: #cubes-thumb"
104- sound =" on: cursor- click; src: audio/ click.ogg " ></a-plane >
107+ sound =" on: click; src: # click-sound " ></a-plane >
105108```
106109
107110Now we have a textured plane that plays a click sound when clicked.
@@ -156,7 +159,7 @@ template and give it a name via `id`:
156159 <script id =" link" >
157160 < a- plane class = " link" height= " 1" width= " 1"
158161 material= " shader: flat; src: #cubes-thumb"
159- sound= " on: cursor- click; src: audio/ click.ogg " >< / a- plane>
162+ sound= " on: click; src: # click-sound " >< / a- plane>
160163 </script >
161164</a-assets >
162165```
@@ -185,7 +188,7 @@ lazy-load the template engine for us. And with Nunjucks, we define a `{{ thumb
185188 <script id =" link" type =" text/nunjucks" >
186189 < a- plane class = " link" height= " 1" width= " 1"
187190 material= " shader: flat; src: {{ thumb }}"
188- sound= " on: cursor- click; src: audio/ click.ogg " >< / a- plane>
191+ sound= " on: click; src: # click-sound " >< / a- plane>
189192 </script >
190193</a-assets >
191194
@@ -230,28 +233,24 @@ listener to do `setAttribute`s on the [scale component][scale] in response to
230233[ event-set component] [ event-set ] that does ` setAttribute ` in response to
231234events.
232235
233- The event-set component defines a unique syntax to be able to define multiple
234- event handlers. Whereas single-property component data represents a value, and
235- multi-property component data represents an object, the event-set component's
236- value is comma-separated and represents an array of objects.
237-
238236Let's attach event listeners on our links to scale them up when they are gazed
239237over, scale them down as they are being clicked, and scale them back when they
240- are no longer gazed upon. We are mimicking CSS hover states. We can specify
238+ are no longer gazed upon. We are mimicking CSS hover states. We can specify
241239event names with ` _event ` properties, and the rest of the properties define the
242- ` setAttibute ` calls:
240+ ` setAttibute ` calls. Note that the event-set component can have [ multiple
241+ instances] [ multiple ] :
243242
244243``` html
245244<a-assets >
246245 <!-- ... -->
247246 <script id =" link" type =" text/nunjucks" >
248247 < a- plane class = " link" height= " 1" width= " 1"
249248 material= " shader: flat; src: {{ thumb }}"
250- sound= " on: cursor- click; src: audio/ click.ogg "
251- event - set = " _event: cursor- mousedown; scale: 1 1 1,
252- _event: cursor- mouseup; scale: 1.2 1.2 1,
253- _event: cursor- mouseenter; scale: 1.2 1.2 1,
254- _event: cursor- mouseleave; scale: 1 1 1" >< / a- plane>
249+ sound= " on: click; src: # click-sound "
250+ event - set__1 = " _event: mousedown; scale: 1 1 1"
251+ event - set__2 = " _event: mouseup; scale: 1.2 1.2 1"
252+ event - set__3 = " _event: mouseenter; scale: 1.2 1.2 1"
253+ event - set__4 = " _event: mouseleave; scale: 1 1 1" >< / a- plane>
255254 </script >
256255</a-assets >
257256```
@@ -349,7 +348,7 @@ AFRAME.registerComponent('update-raycaster', {
349348> View the full [ ` set-image ` component on GitHub] ( https://github.com/aframevr/360-image-viewer-boilerplate/blob/master/components/set-image.js ) .
350349
351350Finally, we write the component that fades the sky into a new 360° ; image
352- once one of the links are clicked. Here is the skeleton for our ` set-image `
351+ once one of the links are clicked. Here is the skeleton for our set-image
353352component.
354353
355354``` js
@@ -444,6 +443,7 @@ And that concludes our 360° image viewer.
444443[ material ] : ../components/material.md
445444[ mixin ] : ../core/mixins.md
446445[ multi-property ] : ../core/component.md#multi-property-component
446+ [ multiple ] : ../core/component.md#multiple-instances
447447[ ngokevin ] : https://github.com/ngokevin
448448[ nunjucks ] : https://mozilla.github.io/nunjucks/
449449[ raycaster ] : http://threejs.org/docs/index.html#Reference/Core/Raycaster
0 commit comments