Project1

标题: 分层显示战斗动画 [打印本页]

作者: doranikofu    时间: 2015-12-14 09:59
标题: 分层显示战斗动画
这次MV的战斗动画似乎是一直显示在所有角色和敌人之上的。如果敌人层叠起来,动画这样放就很没层次感
(, 下载次数: 108)

以前xp的战斗动画的z坐标是跟着人物sprite走的,所以上图中的怪被烧的动画应该在前面的怪后面一层。这次因为mv没有z的概念所以显示就杯具了。同样对主角也有这个问题。如果用横版战斗的话需要考虑这个bug。

然后楼主瞎折腾加了一句addchild,似乎解决了一部分问题
[pre lang="javascript"]//play animation based on battler's z
Sprite_Battler.prototype.setupAnimation = function() {
    while (this._battler.isAnimationRequested()) {
        var data = this._battler.shiftAnimation();
        var animation = $dataAnimations[data.animationId];
        var mirror = data.mirror;
        var delay = animation.position === 3 ? 0 : data.delay;
        this.startAnimation(animation, mirror, delay);
        for (var i = 0; i < this._animationSprites.length; i++) {
            var sprite = this._animationSprites;
            sprite.visible = this._battler.isSpriteVisible();
//如果不是全屏动画,动画作为子类加入
                        if (animation.position < 3) {                       
this.addChild(sprite);
                                };
//修改结束
        }
    }
};[/pre]

于是主角的动画显示似乎是一切正常了,如下图
(, 下载次数: 105)

但是敌人由于显示的结构不一样,杯具如下
(, 下载次数: 99)
本来应该打在蛤蛤上面,结果打到了屏幕中间,敌人的技能准备动画也是同样显示到屏幕中间了。
但是这个位置会根据敌人位置变化,比如最前面第一个蛤蛤的动画就会更靠屏幕左下。也就是说坐标还是根据敌人位置来的。只不过位置不对。
但是尝试在上面的脚本里面重定义sprite.x sprite.y没有任何效果。
不知道具体怎么计算的,感觉只要正确定义一下敌人的坐标就可以正常显示了啊。
作者: dc1988123    时间: 2015-12-14 10:09
是否用了怪物自动排列?火焰可能打的是怪物原来设定的位置。
作者: teatimeif    时间: 2015-12-14 10:11
虽然回答不了LZ的问题 但是要给LZ的画面默默点个赞
顺带问一下 你换了人物的战斗图是静态的还是自己做的几套动作啊
作者: andrewx    时间: 2015-12-14 13:28
本帖最后由 andrewx 于 2015-12-14 14:24 编辑

目测动画离敌人目标的偏移量=敌人离屏幕的偏移量?
.startAnimation这个方法应该是新建动画sprite赋给目标的parent,而动画的实际xy则是根据敌人相对于屏幕的坐标而定。现在强制赋给敌人的话则会在敌人位置的基础上再偏移一次。

动画的位置是在下面的方法里定义的:
[pre lang="javascript" line="1"]Sprite_Animation.prototype.updatePosition = function() {
    if (this._animation.position === 3) {
        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;    //改成0的话动画本身不再偏移
        this.y = this._target.y;    //改成0的话动画本身不再偏移
        if (this.parent === grandparent) {
            this.x += parent.x;
            this.y += parent.y;
        }
        if (this._animation.position === 0) {
            this.y -= this._target.height;
        } else if (this._animation.position === 1) {
            this.y -= this._target.height / 2;
        }
    }
};[/pre]
每次动画刷新都会调用这个方法,所以你一开始直接改xy是无效的,动画位置会一直重新计算
把两个注释的地方改成=0的话就不会往下偏移了,但是会引发其他动画问题,比如地图播放动画的位置错。。。
因此还需改:
[pre lang="javascript" line="1"]
Sprite_Base.prototype.startAnimation = function(animation, mirror, delay) {
    var sprite = new Sprite_Animation();
    sprite.setup(this._effectTarget, animation, mirror, delay);
    //this.parent.addChild(sprite);  换成了下面几句:
    if(animation.position === 3){
        this.parent.addChild(sprite);
    } else {
        this.addChild(sprite);
    }
    //修改结束
    this._animationSprites.push(sprite);
};
[/pre]
这样改了后就不需要你一开始那样addChild了。

稍微测试了下,目前战斗动画和地图动画似乎还算正常,但不保证其他情况下不会出错。。。

p.s. 大爱兰姐谢叔wwww
作者: Denis    时间: 2015-12-15 21:28
呼吸插件是哪一个呀




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X5.0