Need help to position battle animation

Discussion in 'Javascript/Plugin Support' started by Drac00nbeam, Apr 3, 2018.

  1. Drac00nbeam

    Drac00nbeam That will do...for now. Member

    Messages:
    28
    Likes Received:
    1
    First Language:
    German
    Primarily Uses:
    RMMV
    Is there a way to change the position of where a skill animation will play besides the default: Head, Center, Feet, Screen?

    I would like my animation to change the x,y position, depending on what enemy it is being cast upon. The reason is i'm using various sizes of enemies and it's kinda exhausting to make so many animations of one type for so many enemies just to position it the right way. I'm currently using "yanfly's SV enemies" and "yami's sideviewbattler" plugins. I would be glad, if this could be solved, since i'm relatively new to javascript coding.

    The animation id is the same, but the enemies have different sizes.
    normal.png correct position.
    small.png wrong position.
    For the slime, the animation should be positioned a little lower to look realistic.
     
    Last edited: Apr 3, 2018
    #1
  2. Low

    Low Veteran Veteran

    Messages:
    142
    Likes Received:
    141
    First Language:
    english
    Is this only happening on the animated enemies? Because I have been trying to figure out why the animations play on top of my animated enemies but not my party battlers.
     
    #2
  3. Drac00nbeam

    Drac00nbeam That will do...for now. Member

    Messages:
    28
    Likes Received:
    1
    First Language:
    German
    Primarily Uses:
    RMMV
    Not really, i guess it is the same issue with the party battlers, since they too may have different sprite sizes.
    Well i searched the forum for similar threads and found this code within the rpg_sprites.js file:
    Code:
    Sprite_Animation.prototype.updatePosition = function() {
        if (this._animation.position === 3) {                  // for the screen tab
            this.x = this.parent.width / 2;
            this.y = this.parent.height / 2;
        } else {
            var parent = this._target.parent;
            var grandparent = parent ? parent.parent : null;
            this.x = this._target.x;
            this.y = this._target.y;
            if (this.parent === grandparent) {
                this.x += parent.x;
                this.y += parent.y;
            }
            if (this._animation.position === 0) {             // for the head tab
                this.y -= this._target.height;
            } else if (this._animation.position === 1) {      // for the center tab
                this.y -= this._target.height / 2;
            }
        }
    };
    The position number of the animations can also be found within the animation.json file of the data folder.

    It can also be adjusted to specific animations with either by name or id:
    Code:
    if (this._animation.name === "Name of the animation")
    if (this._animation.id === id)
    But the position should be dependent on the enemy as well. Maybe it can be done by simply adding an if-statement with the enemy id, but it'd still be done within a plugin. Since i'm using action sequences it would be better to dynamically add code to the skills notetag.
     
    Last edited: Apr 4, 2018
    #3
  4. Drac00nbeam

    Drac00nbeam That will do...for now. Member

    Messages:
    28
    Likes Received:
    1
    First Language:
    German
    Primarily Uses:
    RMMV
    Bump. I really need to know how you can get the targeted enemy id of the database, because i'm creating a plugin to implement this condition and since there's no default script call to position the animation.
    Code:
    (function() {
    
    var alias_updatePositionOrig = Sprite_Animation.prototype.updatePosition;
        Sprite_Animation.prototype.updatePosition = function() {
            alias_updatePositionOrig.call(this);
                if (this._animation.position === 1) {
                    if (this._animation.id === 146) {
                        if (target.enemyID() === 1) {
                            this.y -= this._target.height / 2 + 200;
                            }
                            else if (target.enemyID() === 2) {
                            this.y -= this._target.height / 2 + 100;
                            }
                            else {
                            }
                    }
                    else if (this._animation.id === 147) {
                        if (target.enemyID() === 1) {
                            this.y -= this._target.height / 2 + 200;
                            }
                            else if (target.enemyID() === 2) {
                            this.y -= this._target.height / 2 + 100;
                            }
                            else {
                            }
                    }
                    
                }
                    
        }
    
    }());
    This doesn't really work, so i suspect there must be some other code for the plugin to work. I would appreciate some help.
     
    #4
  5. Drac00nbeam

    Drac00nbeam That will do...for now. Member

    Messages:
    28
    Likes Received:
    1
    First Language:
    German
    Primarily Uses:
    RMMV
    Bump.
     
    #5
  6. San

    San Villager Member

    Messages:
    10
    Likes Received:
    14
    First Language:
    english
    Primarily Uses:
    RMMV
    [Removed]
     
    Last edited: Apr 13, 2018
    #6
  7. Shaz

    Shaz Veteran Veteran

    Messages:
    37,532
    Likes Received:
    11,248
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    That's a different animation.
     
    #7
  8. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,550
    Likes Received:
    10,494
    First Language:
    English
    Primarily Uses:
    RMVXA
    @San Please do not hijack someone else's thread with your own query, which actually does differ from that of the OP. Their question relates to having the choice of the same animation playing in different places depending on the enemy, and yours is having it always on the centre. I suggest you make your own thread in Javascript/Plugin Support.

    I've moved this thread to Javascript/Plugin Support. Please be sure to post your threads in the correct forum next time. Thank you.

     
    #8
  9. Drac00nbeam

    Drac00nbeam That will do...for now. Member

    Messages:
    28
    Likes Received:
    1
    First Language:
    German
    Primarily Uses:
    RMMV
    Oh sorry if i was mistaken about that, but that's the only code segment i found.
    If there's another code area where you can manipulate the position, could you share it?
    Sorry for the bother and thanks for the reply.
     
    #9
  10. Shaz

    Shaz Veteran Veteran

    Messages:
    37,532
    Likes Received:
    11,248
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    That animation isn't in the default scripts. The OP is using Yanfly's systems. That is where the animation will be set up.
     
    #10
  11. Drac00nbeam

    Drac00nbeam That will do...for now. Member

    Messages:
    28
    Likes Received:
    1
    First Language:
    German
    Primarily Uses:
    RMMV
    Ah ok, i guess it has been aliased in YEP_X_AnimatedSVEnemies plugin:
    Code:
    Yanfly.SVE.Sprite_Animation_updatePosition =
      Sprite_Animation.prototype.updatePosition;
    Sprite_Animation.prototype.updatePosition = function() {
      Yanfly.SVE.Sprite_Animation_updatePosition.call(this);
      this.updateSvePosition();
    };
    
    Sprite_Animation.prototype.updateSvePosition = function() {
      if (typeof this._target.parent._battler != 'undefined'){
        if (this._animation.position !== 3) {
          if (this._animation.position === 0) {
            if (this._target.parent._battler.isEnemy()) {
              this.y -= this._target.parent._texture.height;
            };
          } else if (this._animation.position === 1) {
            if (this._target.parent._battler.isEnemy()) {
              this.y -= this._target.parent._texture.height / 2;
            };
          }
        }
      }
    };
    But i'm not sure how to implement the above conditions in a plugin. The important part is to get the targeted enemy id from the database.
     
    Last edited: Apr 14, 2018
    #11
  12. Coopziana

    Coopziana Veteran Veteran

    Messages:
    115
    Likes Received:
    43
    First Language:
    English
    Did anyone ever find a solution to this, I'm having the same issue, have been fiddling around with the script and I just can't seem to make it work globally for all enemy sizes. I realise the issue is down to the Spritesheet having a lot of empty space vertically. But what I did find was that when using the notetag for <Sprite Height: x> it repositions the location of the state Icons.

    I figured I could try and reference this.sideviewHeight; in the "this.y" section so that I can manually add in a notetag for all enemy Heights and then the script would work out the position of the animation based on that notetag... However, if I add it in, the animation doesn't seem visible at all. I don't get any error messages. I just get the sound effects and screen/target flashes. So I get the feeling the animation is playing but somewhere off screen... so, i'm at a loss now.

    Does anyone have a working solution?

    EDIT: I figured it out!

    Turns out the script that was there was the reference to Sideview Height... Go Figure. So I simply added in an IF Statement to figure out if the enemy is small or large and reposition the animation based on that. Here is the script change:
    Yanfly.SVE.Sprite_Animation_updatePosition =
    Sprite_Animation.prototype.updatePosition;
    Sprite_Animation.prototype.updatePosition = function() {
    Yanfly.SVE.Sprite_Animation_updatePosition.call(this);
    this.updateSvePosition();
    };

    Sprite_Animation.prototype.updateSvePosition = function() {
    if (typeof this._target.parent._battler != 'undefined'){
    if (this._animation.position !== 3) {
    if (this._animation.position === 0) {
    if (this._target.parent._battler.isEnemy()) {
    this.y += this._target.parent._texture.height;
    };
    } else if (this._animation.position === 1) {
    if (this._target.parent._battler.isEnemy()) {
    if (this._target.parent._texture.height <=63) {
    this.y += 100; }
    else { this.y += this._target.parent._texture.height /4; }
    };
    }
    }
    }
    };
     
    Last edited: Jul 12, 2018
    #12
    Scarletia and Jufry_A like this.

Share This Page