Scroll a Horizontal Image

I have this particular image:

ebUoci5.png


that I wanted to use. It works perfectly, but my only problem is the image show AS IS. Is there a way so I can only show a portion of the image, then interchange it or scroll it so it looks like its moving, but in reality the image just interchanges with a portion of it?
You can take a look at this: http://forums.rpgmakerweb.com/index.php?/topic/49033-iavra-gif/

The way i do it:

- When calling Bitmap.load(...), i check the filename and create a container class containing multiple Bitmap instances.

- A Sprite containing this container will only ever load the current frame of the animation.

As long as you are using instances of Sprite (or TilingSprite, since those 2 aren't actually related) and not the Bitmap directly, it will work.
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 
Hi Iavra and Ramiro, thanks for the help.

So after having this code, all I have to do is make a new Sprite or just call it something like

Code:
var cur = new FramedSprite();
yup, you can do that or do it with a bitmap direcly if you already loaded it:

Code:
// assuming this file is named img/system/cursor.pngvar bitmap = ImageManager.loadSystem('cursor');var cur = new FramedSprite(bitmap);
Will try it now, thanks! <3

Original thread: https://forums.rpgmakerweb.com/threads/scroll-a-horizontal-image.50295/