RPG Maker MV角色战斗动画记录

发布于:2024-06-03 ⋅ 阅读:(382) ⋅ 点赞:(0)

角色战斗状态

角色的战斗状态是由 Game_Battler 类中的 _actionState 属性的字符串决定的,它有哪些值呢?

  • undecided 未确定或者说是操作状态
  • inputting 输入
  • waiting 等待
  • acting 活跃
  • done 完成

其他类通过调用 Game_Battler 中判断的方法来确定部分值是否一致来操作人物的精灵。

判断的语句

Game_Battler.prototype.isUndecided = function() {
    return this._actionState === 'undecided';
};

Game_Battler.prototype.isInputting = function() {
    return this._actionState === 'inputting';
};

Game_Battler.prototype.isWaiting = function() {
    return this._actionState === 'waiting';
};

Game_Battler.prototype.isActing = function() {
    return this._actionState === 'acting';
};

赋值

Game_Battler.prototype.setActionState = function(actionState) {
    this._actionState = actionState;
    this.requestMotionRefresh();
};

完成赋值后进行调用请求运动的更新方法,将运动刷新改变成 true 来控制刷新。

战斗管理

/** 战斗管理_变更演员
 * @param {Object} newActorIndex 新演员索引
 * @param {Object} lastActorActionState 最后一个演员操作状态
 */
BattleManager.changeActor = function(newActorIndex, lastActorActionState) {
    var lastActor = this.actor();
    this._actorIndex = newActorIndex;
    var newActor = this.actor();
    if (lastActor) {
        lastActor.setActionState(lastActorActionState);
    }
    if (newActor) {
        newActor.setActionState('inputting');
    }
};

战斗精灵

Sprite_Actor.MOTIONS = {
    walk:     { index: 0,  loop: true  },//向前迈出一步
    wait:     { index: 1,  loop: true  },//正常待机
    chant:    { index: 2,  loop: true  },//吟唱待机
    guard:    { index: 3,  loop: true  },//保护
    damage:   { index: 4,  loop: false },//损坏
    evade:    { index: 5,  loop: false },//闪避
    thrust:   { index: 6,  loop: false },//刺
    swing:    { index: 7,  loop: false },//摆动
    missile:  { index: 8,  loop: false },//投掷
    skill:    { index: 9,  loop: false },//一般技能
    spell:    { index: 10, loop: false },//魔法
    item:     { index: 11, loop: false },//物品使用
    escape:   { index: 12, loop: true  },//逃跑
    victory:  { index: 13, loop: true  },//胜利
    dying:    { index: 14, loop: true  },//重伤
    abnormal: { index: 15, loop: true  },//异常状态
    sleep:    { index: 16, loop: true  },//睡眠
    dead:     { index: 17, loop: true  }//死亡
};

这里面可以看到对应战斗时精灵是有哪些动作的!
图片及链接:
战斗精灵
有兴趣的可以到这个图片连接的网站上看看!!!

创建精灵

Sprite_Actor.prototype.initMembers = function() {
    Sprite_Battler.prototype.initMembers.call(this);
    this._battlerName = '';
    this._motion = null;
    this._motionCount = 0;
    this._pattern = 0;
    this.createShadowSprite();
    this.createWeaponSprite();
    this.createMainSprite();
    this.createStateSprite();
};

这里面初始化了角色的成员,从上到下有战斗图片的名称,运动的动作变量,动作的运动计数,图案数字信息,创建了创建阴影精灵、武器精灵、主体精灵、状态精灵

进行角色的更新

本次探究不会太过深入及条理性的发出代码,请见谅!!!

Sprite_Actor.prototype.update = function() {
    Sprite_Battler.prototype.update.call(this);
    this.updateShadow();
    if (this._actor) {
        this.updateMotion();
    }
};
Sprite_Battler.prototype.update = function() {
    Sprite_Base.prototype.update.call(this);
    if (this._battler) {
        this.updateMain();
        this.updateAnimation();
        this.updateDamagePopup();
        this.updateSelectionEffect();
    } else {
        this.bitmap = null;
    }
};

父类调用了更新主体的方法,更新动画的方法等,自己调用了更新阴影,和运动的方法。
父类调用的主体中调用了角色类的图片更新方法,更新使用的对应角色的图片,之后调用帧的更新方法,更新了每个动作中对应的动画效果,之后更新移动和坐标点。

//更新图片
Sprite_Actor.prototype.updateBitmap = function() {
    Sprite_Battler.prototype.updateBitmap.call(this);
    var name = this._actor.battlerName();
    if (this._battlerName !== name) {
        this._battlerName = name;
        this._mainSprite.bitmap = ImageManager.loadSvActor(name);
    }
};

更新战斗的角色的图片

//更新战斗帧
Sprite_Actor.prototype.updateFrame = function() {
    Sprite_Battler.prototype.updateFrame.call(this);
    var bitmap = this._mainSprite.bitmap;
    if (bitmap) {
        var motionIndex = this._motion ? this._motion.index : 0;
        var pattern = this._pattern < 3 ? this._pattern : 1;
        var cw = bitmap.width / 9;
        var ch = bitmap.height / 6;
        var cx = Math.floor(motionIndex / 6) * 3 + pattern;
        var cy = motionIndex % 6;
        this._mainSprite.setFrame(cx * cw, cy * ch, cw, ch);
    }
};

**motionIndex **中是角色所在对应动作的帧,**pattern 是动作的动画帧,可以看到每个动作是3个动画帧,cx是横向的三个动作坐标,cy是纵向的6个动作的坐标。
其中可以看到
pattern **没有进行改变的值,那它是在哪改变的呢?

//更新运动
Sprite_Actor.prototype.updateMotion = function() {
    this.setupMotion();
    this.setupWeaponAnimation();
    if (this._actor.isMotionRefreshRequested()) {
        this.refreshMotion();
        this._actor.clearMotion();
    }
    this.updateMotionCount();
};
//更新该运动的计数
Sprite_Actor.prototype.updateMotionCount = function() {
    if (this._motion && ++this._motionCount >= this.motionSpeed()) {
        if (this._motion.loop) {
            this._pattern = (this._pattern + 1) % 4;
        } else if (this._pattern < 2) {
            this._pattern++;
        } else {
            this.refreshMotion();
        }
        this._motionCount = 0;
    }
};
//运动休眠
Sprite_Actor.prototype.motionSpeed = function() {
    return 12;
};

就是这里面进行了数字的变更。
最后需要根据操作变更动作,这里用了角色的刷新运动

//刷新运动
Sprite_Actor.prototype.refreshMotion = function() {
    var actor = this._actor;
    var motionGuard = Sprite_Actor.MOTIONS['guard'];
    if (actor) {
        if (this._motion === motionGuard && !BattleManager.isInputting()) {
                return;
        }
        var stateMotion = actor.stateMotionIndex();
        if (actor.isInputting() || actor.isActing()) {
            this.startMotion('walk');console.log("前进表演")
        } else if (stateMotion === 3) {
            this.startMotion('dead');
        } else if (stateMotion === 2) {
            this.startMotion('sleep');console.log("睡眠")
        } else if (actor.isChanting()) {
            this.startMotion('chant');console.log("魔法等待")
        } else if (actor.isGuard() || actor.isGuardWaiting()) {
            this.startMotion('guard');console.log("保护等待")
        } else if (stateMotion === 1) {
            this.startMotion('abnormal');console.log("异常状态")
        } else if (actor.isDying()) {
            this.startMotion('dying');console.log("重伤")
        } else if (actor.isUndecided()) {//是否犹豫(等待)
            this.startMotion('walk');console.log("是否犹豫")
        } else {
            this.startMotion('wait');console.log("前进1")
        }
    }
};

这些部分就行主要的精灵操作了。
看着这么些代码,觉得这游戏开发上很多东西还是耦合的挺多的,因此多事需要进行很多东西的修改也是发现是一件挺麻烦的一件事。


网站公告

今日签到

点亮在社区的每一天
去签到