LoginSignup
1
0

【p5.js】p5.soundをtypescriptで使う

Posted at

方法

  • p5.soundを直接importすると型が取れます
  • global.jsでp5を登録することで、p5.soundを使えるようになります
src/index.ts
import p5 from "p5";
import "p5/lib/addons/p5.sound";
import './global.js';

const sketch = (p: p5) => {
  let sound: p5.SoundFile;

  p.preload = () => {
    sound = p.loadSound('../assets/demo.mp3');
  };

  p.setup = () => {
    p.createCanvas(800, 600);
    sound.loop();
  };

  p.draw = () => {
    // なにか書く
  };
};

new p5(sketch);
src/global.js
import p5 from "p5";
window.p5 = p5;

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0