This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
game.ts
74 lines (64 loc) 路 1.92 KB
/
game.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Entity, GLTFShape, engine, Vector3, Transform, AnimationState, Animator, ActionButton } from 'decentraland-ecs/src'
import { OnPointerDown, OnPointerUp } from 'decentraland-ecs/src/decentraland/UIEvents'
// Add Shark
let shark = new Entity()
shark.addComponent(
new Transform({
position: new Vector3(10, 3, 10)
})
)
shark.addComponent(new GLTFShape('models/shark.gltf'))
// Add animations
/*
NOTE: when you try to get an animation clip that hasn't been created
from a GLTFShape component, the clip is created automatically.
*/
const animator = new Animator()
let clipSwim = new AnimationState('swim')
let clipBite = new AnimationState('bite')
animator.addClip(clipBite)
animator.addClip(clipSwim)
shark.addComponent(animator)
// Activate swim animation
clipSwim.play()
// Add click interaction
let onClickComponent = new OnPointerDown(
e => {
clipBite.playing = !clipBite.playing
}, {
button: ActionButton.POINTER,
hoverText: "OnPointerDown!", distance: 100 })
shark.addComponent(onClickComponent)
shark.addComponent(new OnPointerUp(
e => {}, {
button: ActionButton.POINTER,
hoverText: "OnPointerUp!", distance: 100 }))
// Add shark to engine
engine.addEntity(shark)
// Add second shark
let shark2 = new Entity()
shark2.addComponent(
new Transform({
position: new Vector3(13, 5, 10)
})
)
shark2.addComponent(new GLTFShape('models/shark.gltf'))
shark2.addComponent(new OnPointerDown(
e => {}, {
button: ActionButton.POINTER,
hoverText: "OnPointerDown!", distance: 100 }))
shark2.addComponent(new OnPointerUp(
e => {}, {
button: ActionButton.POINTER,
hoverText: "OnPointerUp!", distance: 100 }))
engine.addEntity(shark2)
// Add 3D model for scenery
const seaBed = new Entity()
seaBed.addComponent(new GLTFShape('models/Underwater.gltf'))
seaBed.addComponent(
new Transform({
position: new Vector3(10, 0, 8),
scale: new Vector3(0.5, 0.5, 0.5)
})
)
engine.addEntity(seaBed)