yes, if you are using sprites:
sprite.frame.set(x, y, width, height);
for a more specific and general rule you can do this:
// let's create our own sprite class for this.function FramedSprite() { // choose the number of frames here this._frames = 5; // in your case 5 images this._frameIndex = 0; // start at index 0 this._frameCount = 0; // start the count at 0 this._frameTime = 60; // switch to the next frame every 60 frames = 1 sec this.initialize.apply(this, arguments);}FramedSprite.prototype = Object.create(Sprite.prototype);FramedSprite.prototype.constructor = FramedSprite;FramedSprite.prototype.update = function () { Sprite.prototype.update.call(this); // do nothing when you didn't add a bitmap to it. if (!this.bitmap) { return; } var w = this.bitmap.width / this._frames; // this is where you make "the rect of the image" this.setFrame(this._frameIndex * w, 0, w / this._frames, this.bitmap.height); // we update our counter here this._frameCount = (this._frameCount + 1) % this._frameTime ; // if the counter is zero, we have to change the frame! if (this._frameCount === 0) { // we update the index here. this._frameIndex = (this._frameIndex + 1) % this._frames; }}This will make your cursor animated and change frame every 60 frames (so 1 per sec) adjust of course that to your style.
Why I'm doing?
(i + 1) % maxYou see that, here for example:
this._frameIndex = (this._frameIndex + 1) % this._frames;You see, first I add 1 (go to the next) and then I get the modulo of that (with %)
A modulo operation means, "do the integer division, and return the rest instead of the value"
This means than the modulo is always this:
Math.floor(a / + (a % === aIn other words... this happens:
1 % 3 is 1, because Math.floor(1 / 3) * 3 + 1 == 1
2 % 3 is 2, because Math.floor(2 / 3) * 3 + 2 == 2
3 % 3 is 0, because Math.floor(3 / 3) * 3 + 0 == 3
4 % 3 is 1, because Math.floor(4 / 3) * 3 + 1 == 4
and it goes on, in a value from 0 to max - 1 (wich is, just what you need)
TL;DR;
setFrame(x, y, width, height); shows a portion of the bitmap, starting from x, y with width and height in size
Will try it now, thanks! <3