If you want a balloon animation to continually run in a loop, you'll have to tap into the update event loop that the Sprite uses in some form or fashion.
The actual Sprite_Balloon that gets constructed has no knowledge of where it's being loaded, though. Its knowledge of its x and y coordinates comes from the parent Sprite_Character that's attached to an event on the map (or the player or follower).
So, you
could add a small Plugin to modify the
Sprite_Character.prototype.updateBalloon function (be aware that this overwrites the original function, so could have compatibility conflicts with other Plugins that try to modify the
updateBalloon method):
Code:
(function() {
Sprite_Character.prototype.updateBalloon = function() {
this.setupBalloon();
if (this._balloonSprite) {
this._balloonSprite.x = this.x;
this._balloonSprite.y = this.y - this.height;
if (this._character._isInfiniteBalloon) {
if (this._balloonSprite._duration === 1) {
this._character._balloonId = this._balloonSprite._balloonId;
this.setupBalloon();
}
} else if (!this._balloonSprite.isPlaying()) {
this.endBalloon();
}
}
};
})();
Then have an event with a script call like:
Code:
var character = $gameMap._events[1];
character._isInfiniteBalloon = true;
character.requestBalloon(1);
And when you want the balloon to stop looping its animation:
Code:
$gameMap._events[1]._isInfiniteBalloon = false;
What the Plugin does is uses the original
updateBalloon method, but adds that new subsection of the conditional where
this._character._isInfiniteBalloon is true. So, if you set a property called _
isInfiniteBalloon on a Game_Character (an event or the player on the map) to true, then when the
updateBalloon method is called every frame and its duration is decreased, when it gets to the end of its duration, instead of calling
endBalloon (which would delete the sprite off the object), it sets up the balloon with the
setupBalloon method again, using the same Id that it's already been using. The setup method will restart the duration and ultimately redraw the balloon sprite.