You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then to make your addon compatible with **both p5.js 1.x and 2.0**, this this line can be removed (the method `loadSound`, in this example, does not need to be registered) and the method can be updated as follows:
// tTis is the check to determine if preload() is being used, as with
110
+
// p5.js 1.x or with the preload compatibility addon. The function
111
+
// returns the soundfile.
112
+
113
+
self._incrementPreload();
114
+
115
+
let player =newp5.SoundFile(
116
+
path,
117
+
function () {
118
+
// The callback indicates to preload() that the file is done loading
119
+
self._decrementPreload();
120
+
}
121
+
);
122
+
return player;
123
+
124
+
}else{
125
+
// Otherwise, async/await is being used, so the function returns a promise,
126
+
// which loads the soundfile asynchronously.
127
+
128
+
returnnewPromise((resolve) => {
129
+
let player =newp5.SoundFile(
130
+
path,
131
+
function () {
132
+
// The callback resolves the promise when the file is done loading
133
+
resolve(player);
134
+
}
135
+
);
136
+
});
137
+
}
138
+
}
139
+
```
140
+
141
+
And that's it! You can check this example of making an addon backwards-compatible and work with p5.js 2.0 here: [the p5.sound.js example](https://github.com/processing/p5.sound.js/commit/608ffa93f241538c4fb353544f6d01275911d212)
142
+
96
143
## …making shapes
97
144
98
145
Short guide coming soon! For now, you can [find out more here](https://github.com/processing/p5.js/issues/6766)
@@ -118,4 +165,3 @@ The below functions are also better supported in JavaScript itself:
0 commit comments