发新话题
打印

我想做一个rpg游戏,现在在作背景移动的实验。急!帮助

我想做一个rpg游戏,现在在作背景移动的实验。急!帮助

我想做一个rpg游戏,现在在作背景移动的实验。基本完成了。可是怎么限制 当人物移动到舞台边缘(_x=0),背景移动停止。怎么来控制呢?请大虾们帮忙了。不胜感激!(代码加在人物影片剪辑上)
代码:
onClipEvent (enterFrame) {

if (Key.isDown(Key.LEFT)) {

if (this._x>80) {
this._x -= 10;
}
else {

_root.map._x += 10;

}
}
if (Key.isDown(Key.RIGHT)) {
if (this._x<480) {
this._x += 10;
} else if (this._x<600){
_root.map._x -= 10;
}
}
if (Key.isDown(Key.UP)) {
if (this._y>100) {
this._y -= 10;
} else {
_root.map._y += 10;
}
}
if (Key.isDown(Key.DOWN)) {
if (this._y<300) {
this._y += 10;
} else {
_root.map._y -= 10;
}
}
}

TOP

请大家帮帮忙了,我在线等

TOP

onClipEvent (enterFrame) {
sd = 20;
if (Key.isDown(67)) {
  sd = 28;
} else {
  sd = 12;
}
if (Key.isDown(Key.UP) && (Key.isDown(Key.RIGHT))) {
  this.gotoAndStop("w");
}
if (Key.isDown(88)) {
  sd = 0;
}
if (Key.isDown(Key.UP)) {
  if (_root.bigmap.bigmap2.map.hitTest(_x, _y-sd, true)) {
   _root.bigmap.bigmap2._y += sd;
   _root.w._y += sd;
   this.gotoAndStop("w");
  }
}
if (Key.isDown(Key.DOWN)) {
  if (_root._root.bigmap.bigmap2.map.hitTest(_x, _y+sd, true)) {
   _root.bigmap.bigmap2._y -= sd;
   _root.w._y -= sd;
   this.gotoAndStop("s");
  }
}
if (Key.isDown(Key.LEFT)) {
  if (_root.bigmap.bigmap2.map.hitTest(_x-sd, _y, true)) {
   _root.bigmap.bigmap2._x += sd;
   _root.w._x += sd;
   this.gotoAndStop("a");
  }
}
if (Key.isDown(Key.RIGHT)) {
  if (_root.bigmap.bigmap2.map.hitTest(_x+sd, _y, true)) {
   _root.bigmap.bigmap2._x -= sd;
   _root.w._x -= sd;
   this.gotoAndStop("d");
  }
}
if ((Key.isDown(Key.RIGHT)) && (Key.isDown(Key.UP))) {
  if (_root.bigmap.bigmap2.map.hitTest(_x+sd, _y, true)) {
   _root.bigmap.bigmap2._x -= sd;
   _root.w._x -= sd;
   this.gotoAndStop("d");
  }
}
}

TOP

回复

你在MAP的上下左右放几个长方形检测区,碰到了让它弹回去。这个方法可行,但你往里面加上几个控制上下左右能否移动的布尔值更好。最好的方法是用一大堆变量控制X、Y速度、加速度、减速度、反弹……。

TOP

高薪诚聘!!!深圳市iLemon网络科技高薪诚聘WebGame程序开发人才加盟

提示: 作者被禁止或删除 内容自动屏蔽

TOP

发新话题