Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Shaker.js 517B

1234567891011121314151617181920212223242526
  1. import Vec2 from "./Vec2.js";
  2. export default class Shaker {
  3. constructor(decay = 7) {
  4. this.vec = new Vec2();
  5. this.decay = decay;
  6. this.shakeX = 0;
  7. this.shakeY = 0;
  8. }
  9. shake(x, y = x) {
  10. this.shakeX = x;
  11. this.shakeY = y;
  12. }
  13. update(dt) {
  14. if (this.shakeX > 0.1)
  15. this.vec.x = (Math.random() - 0.5) * this.shakeX * dt;
  16. if (this.shakeY > 0.1)
  17. this.vec.y = (Math.random() - 0.5) * this.shakeY * dt;
  18. var xRatio = 1 / (1 + (dt * this.decay));
  19. this.shakeX *= xRatio;
  20. this.shakeY *= xRatio;
  21. }
  22. }