感谢楼主让大家分享你的文件,源文件下来后,我修改了一个,好像可行。
“背景”里的的墙MC上的代码:
复制内容到剪贴板
代码:
onEnterFrame=function() {
if(mcWall._y< 0)
mcWall._y+=2;
var Bound=mcWall.getBounds(_root);
var minX=Bound.xMin;
var maxX=Bound.xMax;
var minY=Bound.yMin;
var maxY=Bound.yMax;
this.Text1.text="";
if (this.hitTest(_root.主角)) {
if (Key.isDown(Key.LEFT) and maxX<=_root.主角._x) {
_root.主角._x += 8;
this.Text1.text="顶到右面";
}
if (Key.isDown(Key.RIGHT) and _root.主角._x+_root.主角._width>minX and minY<_root.主角._y) {
_root.主角._x -= 8;
this.Text1.text="顶到左面";
}
if (_root.主角._y-_root.主角._height<=maxY and _root.主角.inAir and _root.主角._x>minX and _root.主角._x-_root.主角._width<maxX) {
this.Text1.text="顶到下面";
mcWall._y=-20;
//这里加上控制主角的代码,撞到墙就得掉下来了,不能冲过墙。
}
}//close ifhit
}//close function [
本帖最后由 光速 于 2008-2-18 14:10 编辑 ]