How to use the decentraland-ecs/src.Component function in decentraland-ecs

To help you get started, we’ve selected a few decentraland-ecs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github decentraland / explorer / kernel / public / test-scenes / 0.90.scene-boundaries / game.ts View on Github external
npcVisibilityTrigger.addComponent(
  new Transform({
    position: new Vector3(-0.25, 4, 0),
    scale: new Vector3(0.3, 0.3, 0.3)
  })
)
npcVisibilityTrigger.addComponent(
  new OnClick(e => {
    let shapeComponent = npcEntity.getComponent(GLTFShape)
    shapeComponent.visible = !shapeComponent.visible
  })
)
engine.addEntity(npcVisibilityTrigger)

// Dynamically scaled platform
@Component('ObjectScaling')
export class ObjectScaling {
  speed: number = 1
  initialScale: number = 1
  targetScale: number = 2
  lerpTime: number = 0
  scalingUp: boolean = true

  constructor(initialScale: number, targetScale: number, speed: number) {
    this.speed = speed
    this.initialScale = initialScale
    this.targetScale = targetScale
  }
}
let scalingCubes = engine.getComponentGroup(ObjectScaling)

export class ObjectScalingSystem implements ISystem {
github decentraland / explorer / kernel / public / test-scenes / 0.90.scene-boundaries / game.ts View on Github external
let scalingSystem = new ObjectScalingSystem()
engine.addSystem(scalingSystem)

let scalingCubeEntity = new Entity()
engine.addEntity(scalingCubeEntity)
scalingCubeEntity.addComponentOrReplace(new BoxShape())
scalingCubeEntity.addComponentOrReplace(
  new Transform({
    position: new Vector3(8, 1, 15),
    scale: new Vector3(2, 2, 2)
  })
)
scalingCubeEntity.addComponentOrReplace(new ObjectScaling(2, 4, 1))

// Rotating platform
@Component('ObjectRotation')
export class ObjectRotation {
  speed: number = 1
  rotationAxis: Vector3

  constructor(speed: number, axis: Vector3) {
    this.speed = speed
    this.rotationAxis = axis
  }
}
let rotatingCubes = engine.getComponentGroup(ObjectRotation)

export class ObjectRotationSystem implements ISystem {
  update(dt: number) {
    for (let cubeEntity of rotatingCubes.entities) {
      let rotationComponent = cubeEntity.getComponent(ObjectRotation)
github decentraland / explorer / kernel / public / test-scenes / 0.90.scene-boundaries / game.ts View on Github external
import { Entity, BoxShape, engine, Vector3, Transform, Component, ISystem, Shape, GLTFShape, Animator, AnimationState, OnClick, NFTShape, Scalar} from 'decentraland-ecs/src'

@Component('Movement')
export class PathMovement {
  waypoints: Vector3[]
  currentWaypoint: number = 0
  targetWaypoint: number = 0
  lerpTime: number = 0
  speed: number = 3
  goingForward: boolean = true

  constructor(newPath: Vector3[], speed: number) {
    this.waypoints = newPath
    this.speed = speed
  }
}

const movingCubes = engine.getComponentGroup(PathMovement)