| 赞 | 2 |
| VIP | |
| 好人卡 | |
| 积分 | 1 |
| 经验 | |
| 最后登录 | 2017-11-7 |
| 在线时间 | 388 小时 |
- 梦石
- 0
- 星屑
- 55
- 在线时间
- 388 小时
- 注册时间
- 2009-8-4
- 回帖
- 212
|
发表于 2015-12-14 13:28:37
|
显示全部楼层
本帖最后由 andrewx 于 2015-12-14 14:24 编辑
目测动画离敌人目标的偏移量=敌人离屏幕的偏移量?
.startAnimation这个方法应该是新建动画sprite赋给目标的parent,而动画的实际xy则是根据敌人相对于屏幕的坐标而定。现在强制赋给敌人的话则会在敌人位置的基础上再偏移一次。
动画的位置是在下面的方法里定义的:
- 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;
- }
- }
- };
复制代码
每次动画刷新都会调用这个方法,所以你一开始直接改xy是无效的,动画位置会一直重新计算
把两个注释的地方改成=0的话就不会往下偏移了,但是会引发其他动画问题,比如地图播放动画的位置错。。。
因此还需改:
- 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);
- };
复制代码
这样改了后就不需要你一开始那样addChild了。
稍微测试了下,目前战斗动画和地图动画似乎还算正常,但不保证其他情况下不会出错。。。
p.s. 大爱兰姐谢叔wwww |
评分
-
查看全部评分
|