I have a sprite with an animation of car. I am trying to chnage the color of car randomly after every loop. but it is not allwoing me to. I tried tinting of sprite, shapecolor, etc. nothing is working
Sadly… There is no way to change a sprite’s tint (by using sprite.tint) anymore. I remember it
having some glitches, now it doesn’t work at all. However, if you’re really determined, you could draw the images yourself and use a function I created:
function changeTintOnAnimationEnd(sprite, totalFrames, callback) {
if(sprite.currentExpectedFrame == undefined) {
sprite.currentExpectedFrame = 0;
}
if(sprite.frameDidChange()) {
sprite.currentExpectedFrame++;
if(totalFrames == sprite.currentExpectedFrame) {
sprite.currentExpectedFrame = 0;
callback();
}
}
}
It accepts 3 parameters, the sprite, the total frames and the callback. The reason I created it for is because there’s literally no reason to get the current frame of a sprite, and this will only fire once when the sprite’s animation loop restarts.
For the callback, you could maybe choose a random car animation. However, this isn’t very flexible, and if you want to finish that project you’d have more luck to do so with normal p5.js, but that’s more advanced, and obviously no sprites.