[SOLVED] Game_Screen: updateShake()

This is the function Game_Screen.prototype.updateShake (located in the rpg_objects.js file):
Game_Screen.prototype.updateShake.png


I am interested to know / am wondering if anybody can tell me where / what is processing the $gameScreen._shake and $gameScreen._direction values that are being altered during this function?

I am assuming that somewhere, these parameters are being taken and used to dictate which way the screen should move every update to create the shake effect... I just can't find where.

I tried looking through the other core JS files but came up blank.

Thanks in advance!
I believe _shakeDirection is internal, i.e. it's only used to determine how _shake changes in this method. _shake itself determines a display offset for the current spriteset, cf. rpg_sprites.js:
JavaScript:
Spriteset_Base.prototype.updatePosition = function() {
    var screen = $gameScreen;
    var scale = screen.zoomScale();
    this.scale.x = scale;
    this.scale.y = scale;
    this.x = Math.round(-screen.zoomX() * (scale - 1));
    this.y = Math.round(-screen.zoomY() * (scale - 1));
    this.x += Math.round(screen.shake());
};
I.e. the x-position of all spritesets is offset by the screen's current _shake value. If the spriteset is offset, all its sprites will also be offset. 🙂
I believe _shakeDirection is internal, i.e. it's only used to determine how _shake changes in this method. _shake itself determines a display offset for the current spriteset, cf. rpg_sprites.js:
JavaScript:
Spriteset_Base.prototype.updatePosition = function() {[/INDENT]
[INDENT]    var screen = $gameScreen;[/INDENT]
[INDENT]    var scale = screen.zoomScale();[/INDENT]
[INDENT]    this.scale.x = scale;[/INDENT]
[INDENT]    this.scale.y = scale;[/INDENT]
[INDENT]    this.x = Math.round(-screen.zoomX() * (scale - 1));[/INDENT]
[INDENT]    this.y = Math.round(-screen.zoomY() * (scale - 1));[/INDENT]
[INDENT]    this.x += Math.round(screen.shake());[/INDENT]
[INDENT]};
I.e. the x-position of all spritesets is offset by the screen's current _shake value. If the spriteset is offset, all its sprites will also be offset. 🙂

Excellent! I appreciate the explanation. Thank you 🙂
Yea, it's only shake left and right.

_shakeDirection only have 1 and -1 outcome, which is right and left respectively.

For example, if you put 5 as power, the expected outcome would be like this :
0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -4, -3, -2, -1, 0

Then combine that with speed for the frequency.

The code looks a bit cringe, to be honest... but all is fair as long as it works I guess.
Yea, it's only shake left and right.

_shakeDirection only have 1 and -1 outcome, which is right and left respectively.

For example, if you put 5 as power, the expected outcome would be like this :
0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -4, -3, -2, -1, 0

Then combine that with speed for the frequency.

The code looks a bit cringe, to be honest... but all is fair as long as it works I guess.
Thank you!
@caethyril and @Kuro DCupu - thank you again... it works!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-game_screen-updateshake.122849/